* somsolib.c (dld_cache): Replace boolean by int for field is_valid.
[deliverable/binutils-gdb.git] / gdb / language.c
CommitLineData
c906108c 1/* Multiple source language support for GDB.
6c6ea35e 2 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002
b6ba6518 3 Free Software Foundation, Inc.
c906108c
SS
4 Contributed by the Department of Computer Science at the State University
5 of New York at Buffalo.
6
c5aa993b 7 This file is part of GDB.
c906108c 8
c5aa993b
JM
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
c906108c 13
c5aa993b
JM
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
c906108c 18
c5aa993b
JM
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
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"
c906108c 45
a14ed312 46extern void _initialize_language (void);
392a587b 47
a14ed312 48static void show_language_command (char *, int);
c906108c 49
a14ed312 50static void set_language_command (char *, int);
c906108c 51
a14ed312 52static void show_type_command (char *, int);
c906108c 53
a14ed312 54static void set_type_command (char *, int);
c906108c 55
a14ed312 56static void show_range_command (char *, int);
c906108c 57
a14ed312 58static void set_range_command (char *, int);
c906108c 59
63872f9d
JG
60static void show_case_command (char *, int);
61
62static void set_case_command (char *, int);
63
64static void set_case_str (void);
65
a14ed312 66static void set_range_str (void);
c906108c 67
a14ed312 68static void set_type_str (void);
c906108c 69
a14ed312 70static void set_lang_str (void);
c906108c 71
a14ed312 72static void unk_lang_error (char *);
c906108c 73
a14ed312 74static int unk_lang_parser (void);
c906108c 75
a14ed312 76static void show_check (char *, int);
c906108c 77
a14ed312 78static void set_check (char *, int);
c906108c 79
63872f9d 80static void set_type_range_case (void);
c906108c 81
d9fcf2fb 82static void unk_lang_emit_char (int c, struct ui_file *stream, int quoter);
c906108c 83
d9fcf2fb 84static void unk_lang_printchar (int c, struct ui_file *stream);
c906108c 85
d9fcf2fb
JM
86static void unk_lang_printstr (struct ui_file * stream, char *string,
87 unsigned int length, int width,
88 int force_ellipses);
c906108c 89
a14ed312 90static struct type *unk_lang_create_fundamental_type (struct objfile *, int);
c906108c 91
d9fcf2fb
JM
92static void unk_lang_print_type (struct type *, char *, struct ui_file *,
93 int, int);
c906108c 94
d9fcf2fb
JM
95static int unk_lang_val_print (struct type *, char *, int, CORE_ADDR,
96 struct ui_file *, int, int, int,
97 enum val_prettyprint);
c906108c 98
3d6d86c6 99static int unk_lang_value_print (struct value *, struct ui_file *, int, enum val_prettyprint);
c906108c
SS
100
101/* Forward declaration */
102extern const struct language_defn unknown_language_defn;
c5aa993b 103
c906108c 104/* The current (default at startup) state of type and range checking.
c5aa993b
JM
105 (If the modes are set to "auto", though, these are changed based
106 on the default language at startup, and then again based on the
107 language of the first source file. */
c906108c
SS
108
109enum range_mode range_mode = range_mode_auto;
110enum range_check range_check = range_check_off;
111enum type_mode type_mode = type_mode_auto;
112enum type_check type_check = type_check_off;
63872f9d
JG
113enum case_mode case_mode = case_mode_auto;
114enum case_sensitivity case_sensitivity = case_sensitive_on;
c906108c
SS
115
116/* The current language and language_mode (see language.h) */
117
118const struct language_defn *current_language = &unknown_language_defn;
119enum language_mode language_mode = language_mode_auto;
120
121/* The language that the user expects to be typing in (the language
122 of main(), or the last language we notified them about, or C). */
123
124const struct language_defn *expected_language;
125
126/* The list of supported languages. The list itself is malloc'd. */
127
128static const struct language_defn **languages;
129static unsigned languages_size;
130static unsigned languages_allocsize;
131#define DEFAULT_ALLOCSIZE 4
132
133/* The "set language/type/range" commands all put stuff in these
134 buffers. This is to make them work as set/show commands. The
135 user's string is copied here, then the set_* commands look at
136 them and update them to something that looks nice when it is
137 printed out. */
138
139static char *language;
140static char *type;
141static char *range;
63872f9d 142static char *case_sensitive;
c906108c
SS
143
144/* Warning issued when current_language and the language of the current
145 frame do not match. */
146char lang_frame_mismatch_warn[] =
c5aa993b 147"Warning: the current language does not match this frame.";
c906108c 148\f
c5aa993b 149
c906108c
SS
150/* This page contains the functions corresponding to GDB commands
151 and their helpers. */
152
153/* Show command. Display a warning if the language set
154 does not match the frame. */
155static void
fba45db2 156show_language_command (char *ignore, int from_tty)
c906108c 157{
c5aa993b 158 enum language flang; /* The language of the current frame */
c906108c 159
c5aa993b
JM
160 flang = get_frame_language ();
161 if (flang != language_unknown &&
162 language_mode == language_mode_manual &&
163 current_language->la_language != flang)
164 printf_filtered ("%s\n", lang_frame_mismatch_warn);
c906108c
SS
165}
166
167/* Set command. Change the current working language. */
168static void
fba45db2 169set_language_command (char *ignore, int from_tty)
c906108c
SS
170{
171 int i;
172 enum language flang;
173 char *err_lang;
174
175 if (!language || !language[0])
176 {
c5aa993b 177 printf_unfiltered ("The currently understood settings are:\n\n");
c906108c
SS
178 printf_unfiltered ("local or auto Automatic setting based on source file\n");
179
180 for (i = 0; i < languages_size; ++i)
181 {
182 /* Already dealt with these above. */
183 if (languages[i]->la_language == language_unknown
184 || languages[i]->la_language == language_auto)
185 continue;
186
187 /* FIXME for now assume that the human-readable name is just
188 a capitalization of the internal name. */
189 printf_unfiltered ("%-16s Use the %c%s language\n",
190 languages[i]->la_name,
c5aa993b
JM
191 /* Capitalize first letter of language
192 name. */
c906108c
SS
193 toupper (languages[i]->la_name[0]),
194 languages[i]->la_name + 1);
195 }
196 /* Restore the silly string. */
c5aa993b 197 set_language (current_language->la_language);
c906108c
SS
198 return;
199 }
200
201 /* Search the list of languages for a match. */
c5aa993b
JM
202 for (i = 0; i < languages_size; i++)
203 {
204 if (STREQ (languages[i]->la_name, language))
205 {
206 /* Found it! Go into manual mode, and use this language. */
207 if (languages[i]->la_language == language_auto)
208 {
209 /* Enter auto mode. Set to the current frame's language, if known. */
210 language_mode = language_mode_auto;
211 flang = get_frame_language ();
212 if (flang != language_unknown)
213 set_language (flang);
214 expected_language = current_language;
215 return;
216 }
217 else
218 {
219 /* Enter manual mode. Set the specified language. */
220 language_mode = language_mode_manual;
221 current_language = languages[i];
63872f9d 222 set_type_range_case ();
c5aa993b
JM
223 set_lang_str ();
224 expected_language = current_language;
225 return;
226 }
227 }
c906108c 228 }
c906108c
SS
229
230 /* Reset the language (esp. the global string "language") to the
231 correct values. */
c5aa993b 232 err_lang = savestring (language, strlen (language));
b8c9b27d 233 make_cleanup (xfree, err_lang); /* Free it after error */
c5aa993b
JM
234 set_language (current_language->la_language);
235 error ("Unknown language `%s'.", err_lang);
c906108c
SS
236}
237
238/* Show command. Display a warning if the type setting does
239 not match the current language. */
240static void
fba45db2 241show_type_command (char *ignore, int from_tty)
c906108c 242{
c5aa993b
JM
243 if (type_check != current_language->la_type_check)
244 printf_unfiltered (
245 "Warning: the current type check setting does not match the language.\n");
c906108c
SS
246}
247
248/* Set command. Change the setting for type checking. */
249static void
fba45db2 250set_type_command (char *ignore, int from_tty)
c906108c 251{
c5aa993b
JM
252 if (STREQ (type, "on"))
253 {
c906108c
SS
254 type_check = type_check_on;
255 type_mode = type_mode_manual;
c5aa993b
JM
256 }
257 else if (STREQ (type, "warn"))
258 {
c906108c
SS
259 type_check = type_check_warn;
260 type_mode = type_mode_manual;
c5aa993b
JM
261 }
262 else if (STREQ (type, "off"))
263 {
c906108c
SS
264 type_check = type_check_off;
265 type_mode = type_mode_manual;
c5aa993b
JM
266 }
267 else if (STREQ (type, "auto"))
268 {
c906108c 269 type_mode = type_mode_auto;
63872f9d 270 set_type_range_case ();
c906108c 271 /* Avoid hitting the set_type_str call below. We
63872f9d 272 did it in set_type_range_case. */
c906108c 273 return;
c5aa993b 274 }
c4093a6a
JM
275 else
276 {
277 warning ("Unrecognized type check setting: \"%s\"", type);
278 }
c5aa993b
JM
279 set_type_str ();
280 show_type_command ((char *) NULL, from_tty);
c906108c
SS
281}
282
283/* Show command. Display a warning if the range setting does
284 not match the current language. */
285static void
fba45db2 286show_range_command (char *ignore, int from_tty)
c906108c
SS
287{
288
c5aa993b
JM
289 if (range_check != current_language->la_range_check)
290 printf_unfiltered (
291 "Warning: the current range check setting does not match the language.\n");
c906108c
SS
292}
293
294/* Set command. Change the setting for range checking. */
295static void
fba45db2 296set_range_command (char *ignore, int from_tty)
c906108c 297{
c5aa993b
JM
298 if (STREQ (range, "on"))
299 {
c906108c
SS
300 range_check = range_check_on;
301 range_mode = range_mode_manual;
c5aa993b
JM
302 }
303 else if (STREQ (range, "warn"))
304 {
c906108c
SS
305 range_check = range_check_warn;
306 range_mode = range_mode_manual;
c5aa993b
JM
307 }
308 else if (STREQ (range, "off"))
309 {
c906108c
SS
310 range_check = range_check_off;
311 range_mode = range_mode_manual;
c5aa993b
JM
312 }
313 else if (STREQ (range, "auto"))
314 {
c906108c 315 range_mode = range_mode_auto;
63872f9d 316 set_type_range_case ();
c906108c 317 /* Avoid hitting the set_range_str call below. We
63872f9d 318 did it in set_type_range_case. */
c906108c 319 return;
c5aa993b 320 }
c4093a6a
JM
321 else
322 {
323 warning ("Unrecognized range check setting: \"%s\"", range);
324 }
c5aa993b
JM
325 set_range_str ();
326 show_range_command ((char *) 0, from_tty);
c906108c
SS
327}
328
63872f9d
JG
329/* Show command. Display a warning if the case sensitivity setting does
330 not match the current language. */
331static void
ad525611 332show_case_command (char *ignore, int from_tty)
63872f9d
JG
333{
334 if (case_sensitivity != current_language->la_case_sensitivity)
335 printf_unfiltered(
336"Warning: the current case sensitivity setting does not match the language.\n");
337}
338
339/* Set command. Change the setting for case sensitivity. */
340static void
ad525611 341set_case_command (char *ignore, int from_tty)
63872f9d
JG
342{
343 if (STREQ (case_sensitive, "on"))
344 {
345 case_sensitivity = case_sensitive_on;
346 case_mode = case_mode_manual;
347 }
348 else if (STREQ (case_sensitive, "off"))
349 {
350 case_sensitivity = case_sensitive_off;
351 case_mode = case_mode_manual;
352 }
353 else if (STREQ (case_sensitive, "auto"))
354 {
355 case_mode = case_mode_auto;
356 set_type_range_case ();
357 /* Avoid hitting the set_case_str call below. We
358 did it in set_type_range_case. */
359 return;
360 }
361 else
362 {
363 warning ("Unrecognized case-sensitive setting: \"%s\"", case_sensitive);
364 }
365 set_case_str();
366 show_case_command ((char *) NULL, from_tty);
367}
368
369/* Set the status of range and type checking and case sensitivity based on
c906108c
SS
370 the current modes and the current language.
371 If SHOW is non-zero, then print out the current language,
372 type and range checking status. */
373static void
63872f9d 374set_type_range_case (void)
c906108c
SS
375{
376
377 if (range_mode == range_mode_auto)
378 range_check = current_language->la_range_check;
379
380 if (type_mode == type_mode_auto)
381 type_check = current_language->la_type_check;
382
63872f9d
JG
383 if (case_mode == case_mode_auto)
384 case_sensitivity = current_language->la_case_sensitivity;
385
c5aa993b
JM
386 set_type_str ();
387 set_range_str ();
63872f9d 388 set_case_str ();
c906108c
SS
389}
390
391/* Set current language to (enum language) LANG. Returns previous language. */
392
393enum language
fba45db2 394set_language (enum language lang)
c906108c
SS
395{
396 int i;
397 enum language prev_language;
398
399 prev_language = current_language->la_language;
400
c5aa993b
JM
401 for (i = 0; i < languages_size; i++)
402 {
403 if (languages[i]->la_language == lang)
404 {
405 current_language = languages[i];
63872f9d 406 set_type_range_case ();
c5aa993b
JM
407 set_lang_str ();
408 break;
409 }
c906108c 410 }
c906108c
SS
411
412 return prev_language;
413}
414\f
415/* This page contains functions that update the global vars
416 language, type and range. */
417static void
fba45db2 418set_lang_str (void)
c906108c 419{
c5aa993b 420 char *prefix = "";
c906108c 421
ccdaf797 422 if (language)
b8c9b27d 423 xfree (language);
c5aa993b
JM
424 if (language_mode == language_mode_auto)
425 prefix = "auto; currently ";
c906108c 426
c5aa993b 427 language = concat (prefix, current_language->la_name, NULL);
c906108c
SS
428}
429
430static void
fba45db2 431set_type_str (void)
c906108c 432{
c4093a6a 433 char *tmp = NULL, *prefix = "";
c906108c 434
ccdaf797 435 if (type)
b8c9b27d 436 xfree (type);
c5aa993b
JM
437 if (type_mode == type_mode_auto)
438 prefix = "auto; currently ";
c906108c 439
c5aa993b
JM
440 switch (type_check)
441 {
442 case type_check_on:
c906108c
SS
443 tmp = "on";
444 break;
c5aa993b 445 case type_check_off:
c906108c
SS
446 tmp = "off";
447 break;
c5aa993b 448 case type_check_warn:
c906108c
SS
449 tmp = "warn";
450 break;
c5aa993b 451 default:
c906108c 452 error ("Unrecognized type check setting.");
c5aa993b 453 }
c906108c 454
c5aa993b 455 type = concat (prefix, tmp, NULL);
c906108c
SS
456}
457
458static void
fba45db2 459set_range_str (void)
c906108c 460{
c5aa993b 461 char *tmp, *pref = "";
c906108c 462
c5aa993b
JM
463 if (range_mode == range_mode_auto)
464 pref = "auto; currently ";
c906108c 465
c5aa993b
JM
466 switch (range_check)
467 {
468 case range_check_on:
c906108c
SS
469 tmp = "on";
470 break;
c5aa993b 471 case range_check_off:
c906108c
SS
472 tmp = "off";
473 break;
c5aa993b 474 case range_check_warn:
c906108c
SS
475 tmp = "warn";
476 break;
c5aa993b 477 default:
c906108c 478 error ("Unrecognized range check setting.");
c5aa993b 479 }
c906108c 480
ccdaf797 481 if (range)
b8c9b27d 482 xfree (range);
c5aa993b 483 range = concat (pref, tmp, NULL);
c906108c
SS
484}
485
63872f9d 486static void
5ae5f592 487set_case_str (void)
63872f9d
JG
488{
489 char *tmp = NULL, *prefix = "";
490
491 if (case_mode==case_mode_auto)
492 prefix = "auto; currently ";
493
494 switch (case_sensitivity)
495 {
496 case case_sensitive_on:
497 tmp = "on";
498 break;
499 case case_sensitive_off:
500 tmp = "off";
501 break;
502 default:
503 error ("Unrecognized case-sensitive setting.");
504 }
505
b8c9b27d 506 xfree (case_sensitive);
63872f9d
JG
507 case_sensitive = concat (prefix, tmp, NULL);
508}
c906108c
SS
509
510/* Print out the current language settings: language, range and
511 type checking. If QUIETLY, print only what has changed. */
512
513void
fba45db2 514language_info (int quietly)
c906108c
SS
515{
516 if (quietly && expected_language == current_language)
517 return;
518
519 expected_language = current_language;
c5aa993b
JM
520 printf_unfiltered ("Current language: %s\n", language);
521 show_language_command ((char *) 0, 1);
c906108c
SS
522
523 if (!quietly)
524 {
c5aa993b
JM
525 printf_unfiltered ("Type checking: %s\n", type);
526 show_type_command ((char *) 0, 1);
527 printf_unfiltered ("Range checking: %s\n", range);
528 show_range_command ((char *) 0, 1);
63872f9d
JG
529 printf_unfiltered ("Case sensitivity: %s\n", case_sensitive);
530 show_case_command ((char *) 0, 1);
c906108c
SS
531 }
532}
533\f
534/* Return the result of a binary operation. */
535
c5aa993b 536#if 0 /* Currently unused */
c906108c
SS
537
538struct type *
3d6d86c6 539binop_result_type (struct value *v1, struct value *v2)
c906108c 540{
c5aa993b
JM
541 int size, uns;
542 struct type *t1 = check_typedef (VALUE_TYPE (v1));
543 struct type *t2 = check_typedef (VALUE_TYPE (v2));
544
545 int l1 = TYPE_LENGTH (t1);
546 int l2 = TYPE_LENGTH (t2);
547
548 switch (current_language->la_language)
549 {
550 case language_c:
551 case language_cplus:
eb392fbf 552 case language_objc:
c5aa993b
JM
553 if (TYPE_CODE (t1) == TYPE_CODE_FLT)
554 return TYPE_CODE (t2) == TYPE_CODE_FLT && l2 > l1 ?
555 VALUE_TYPE (v2) : VALUE_TYPE (v1);
556 else if (TYPE_CODE (t2) == TYPE_CODE_FLT)
557 return TYPE_CODE (t1) == TYPE_CODE_FLT && l1 > l2 ?
558 VALUE_TYPE (v1) : VALUE_TYPE (v2);
559 else if (TYPE_UNSIGNED (t1) && l1 > l2)
560 return VALUE_TYPE (v1);
561 else if (TYPE_UNSIGNED (t2) && l2 > l1)
562 return VALUE_TYPE (v2);
563 else /* Both are signed. Result is the longer type */
564 return l1 > l2 ? VALUE_TYPE (v1) : VALUE_TYPE (v2);
c906108c 565 break;
c5aa993b 566 case language_m2:
c906108c 567 /* If we are doing type-checking, l1 should equal l2, so this is
c5aa993b
JM
568 not needed. */
569 return l1 > l2 ? VALUE_TYPE (v1) : VALUE_TYPE (v2);
c906108c 570 break;
db034ac5
AC
571 /* OBSOLETE case language_chill: */
572 /* OBSOLETE error ("Missing Chill support in function binop_result_check."); */ /*FIXME */
c5aa993b 573 }
e1e9e218 574 internal_error (__FILE__, __LINE__, "failed internal consistency check");
c5aa993b 575 return (struct type *) 0; /* For lint */
c906108c
SS
576}
577
c5aa993b 578#endif /* 0 */
c906108c 579\f
c5aa993b 580
c906108c
SS
581/* This page contains functions that return format strings for
582 printf for printing out numbers in different formats */
583
584/* Returns the appropriate printf format for hexadecimal
585 numbers. */
586char *
fba45db2 587local_hex_format_custom (char *pre)
c906108c 588{
c5aa993b
JM
589 static char form[50];
590
591 strcpy (form, local_hex_format_prefix ());
592 strcat (form, "%");
593 strcat (form, pre);
594 strcat (form, local_hex_format_specifier ());
595 strcat (form, local_hex_format_suffix ());
596 return form;
c906108c
SS
597}
598
14a5e767 599/* Converts a LONGEST to custom hexadecimal and stores it in a static
c906108c
SS
600 string. Returns a pointer to this string. */
601char *
14a5e767 602local_hex_string (LONGEST num)
c906108c 603{
14a5e767 604 return local_hex_string_custom (num, "l");
c906108c
SS
605}
606
c4093a6a
JM
607/* Converts a LONGEST number to custom hexadecimal and stores it in a static
608 string. Returns a pointer to this string. Note that the width parameter
609 should end with "l", e.g. "08l" as with calls to local_hex_string_custom */
610
611char *
14a5e767 612local_hex_string_custom (LONGEST num, char *width)
c4093a6a
JM
613{
614#define RESULT_BUF_LEN 50
615 static char res2[RESULT_BUF_LEN];
616 char format[RESULT_BUF_LEN];
c4093a6a
JM
617 int field_width;
618 int num_len;
619 int num_pad_chars;
620 char *pad_char; /* string with one character */
621 int pad_on_left;
622 char *parse_ptr;
623 char temp_nbr_buf[RESULT_BUF_LEN];
14a5e767 624
17df2af6 625 /* Use phex_nz to print the number into a string, then
c4093a6a
JM
626 build the result string from local_hex_format_prefix, padding and
627 the hex representation as indicated by "width". */
17df2af6 628 strcpy (temp_nbr_buf, phex_nz (num, sizeof (num)));
c4093a6a
JM
629 /* parse width */
630 parse_ptr = width;
631 pad_on_left = 1;
632 pad_char = " ";
633 if (*parse_ptr == '-')
634 {
635 parse_ptr++;
636 pad_on_left = 0;
637 }
638 if (*parse_ptr == '0')
639 {
640 parse_ptr++;
641 if (pad_on_left)
642 pad_char = "0"; /* If padding is on the right, it is blank */
643 }
644 field_width = atoi (parse_ptr);
645 num_len = strlen (temp_nbr_buf);
646 num_pad_chars = field_width - strlen (temp_nbr_buf); /* possibly negative */
647
648 if (strlen (local_hex_format_prefix ()) + num_len + num_pad_chars
7aedc9f8 649 >= RESULT_BUF_LEN) /* paranoia */
8e65ff28 650 internal_error (__FILE__, __LINE__,
14a5e767 651 "local_hex_string_custom: insufficient space to store result");
c4093a6a
JM
652
653 strcpy (res2, local_hex_format_prefix ());
654 if (pad_on_left)
655 {
656 while (num_pad_chars > 0)
657 {
658 strcat (res2, pad_char);
659 num_pad_chars--;
660 }
661 }
662 strcat (res2, temp_nbr_buf);
663 if (!pad_on_left)
664 {
665 while (num_pad_chars > 0)
666 {
667 strcat (res2, pad_char);
668 num_pad_chars--;
669 }
670 }
671 return res2;
c4093a6a 672
14a5e767 673} /* local_hex_string_custom */
c4093a6a 674
c906108c
SS
675/* Returns the appropriate printf format for octal
676 numbers. */
677char *
fba45db2 678local_octal_format_custom (char *pre)
c906108c 679{
c5aa993b
JM
680 static char form[50];
681
682 strcpy (form, local_octal_format_prefix ());
683 strcat (form, "%");
684 strcat (form, pre);
685 strcat (form, local_octal_format_specifier ());
686 strcat (form, local_octal_format_suffix ());
687 return form;
c906108c
SS
688}
689
690/* Returns the appropriate printf format for decimal numbers. */
691char *
fba45db2 692local_decimal_format_custom (char *pre)
c906108c 693{
c5aa993b
JM
694 static char form[50];
695
696 strcpy (form, local_decimal_format_prefix ());
697 strcat (form, "%");
698 strcat (form, pre);
699 strcat (form, local_decimal_format_specifier ());
700 strcat (form, local_decimal_format_suffix ());
701 return form;
c906108c
SS
702}
703\f
704#if 0
705/* This page contains functions that are used in type/range checking.
706 They all return zero if the type/range check fails.
707
708 It is hoped that these will make extending GDB to parse different
709 languages a little easier. These are primarily used in eval.c when
710 evaluating expressions and making sure that their types are correct.
711 Instead of having a mess of conjucted/disjuncted expressions in an "if",
712 the ideas of type can be wrapped up in the following functions.
713
714 Note that some of them are not currently dependent upon which language
715 is currently being parsed. For example, floats are the same in
716 C and Modula-2 (ie. the only floating point type has TYPE_CODE of
717 TYPE_CODE_FLT), while booleans are different. */
718
719/* Returns non-zero if its argument is a simple type. This is the same for
720 both Modula-2 and for C. In the C case, TYPE_CODE_CHAR will never occur,
721 and thus will never cause the failure of the test. */
722int
fba45db2 723simple_type (struct type *type)
c906108c
SS
724{
725 CHECK_TYPEDEF (type);
c5aa993b
JM
726 switch (TYPE_CODE (type))
727 {
728 case TYPE_CODE_INT:
729 case TYPE_CODE_CHAR:
730 case TYPE_CODE_ENUM:
731 case TYPE_CODE_FLT:
732 case TYPE_CODE_RANGE:
733 case TYPE_CODE_BOOL:
734 return 1;
c906108c 735
c5aa993b
JM
736 default:
737 return 0;
738 }
c906108c
SS
739}
740
741/* Returns non-zero if its argument is of an ordered type.
742 An ordered type is one in which the elements can be tested for the
743 properties of "greater than", "less than", etc, or for which the
744 operations "increment" or "decrement" make sense. */
745int
fba45db2 746ordered_type (struct type *type)
c906108c
SS
747{
748 CHECK_TYPEDEF (type);
c5aa993b
JM
749 switch (TYPE_CODE (type))
750 {
751 case TYPE_CODE_INT:
752 case TYPE_CODE_CHAR:
753 case TYPE_CODE_ENUM:
754 case TYPE_CODE_FLT:
755 case TYPE_CODE_RANGE:
756 return 1;
c906108c 757
c5aa993b
JM
758 default:
759 return 0;
760 }
c906108c
SS
761}
762
763/* Returns non-zero if the two types are the same */
764int
fba45db2 765same_type (struct type *arg1, struct type *arg2)
c906108c
SS
766{
767 CHECK_TYPEDEF (type);
c5aa993b
JM
768 if (structured_type (arg1) ? !structured_type (arg2) : structured_type (arg2))
769 /* One is structured and one isn't */
770 return 0;
771 else if (structured_type (arg1) && structured_type (arg2))
772 return arg1 == arg2;
773 else if (numeric_type (arg1) && numeric_type (arg2))
774 return (TYPE_CODE (arg2) == TYPE_CODE (arg1)) &&
775 (TYPE_UNSIGNED (arg1) == TYPE_UNSIGNED (arg2))
776 ? 1 : 0;
777 else
778 return arg1 == arg2;
c906108c
SS
779}
780
781/* Returns non-zero if the type is integral */
782int
fba45db2 783integral_type (struct type *type)
c906108c
SS
784{
785 CHECK_TYPEDEF (type);
c5aa993b
JM
786 switch (current_language->la_language)
787 {
788 case language_c:
789 case language_cplus:
eb392fbf 790 case language_objc:
c5aa993b
JM
791 return (TYPE_CODE (type) != TYPE_CODE_INT) &&
792 (TYPE_CODE (type) != TYPE_CODE_ENUM) ? 0 : 1;
793 case language_m2:
750ba382 794 case language_pascal:
c5aa993b 795 return TYPE_CODE (type) != TYPE_CODE_INT ? 0 : 1;
db034ac5
AC
796 /* OBSOLETE case language_chill: */
797 /* OBSOLETE error ("Missing Chill support in function integral_type."); *//*FIXME */
c5aa993b 798 default:
c906108c 799 error ("Language not supported.");
c5aa993b 800 }
c906108c
SS
801}
802
803/* Returns non-zero if the value is numeric */
804int
fba45db2 805numeric_type (struct type *type)
c906108c
SS
806{
807 CHECK_TYPEDEF (type);
c5aa993b
JM
808 switch (TYPE_CODE (type))
809 {
810 case TYPE_CODE_INT:
811 case TYPE_CODE_FLT:
812 return 1;
c906108c 813
c5aa993b
JM
814 default:
815 return 0;
816 }
c906108c
SS
817}
818
819/* Returns non-zero if the value is a character type */
820int
fba45db2 821character_type (struct type *type)
c906108c
SS
822{
823 CHECK_TYPEDEF (type);
c5aa993b
JM
824 switch (current_language->la_language)
825 {
db034ac5 826 /* OBSOLETE case language_chill: */
c5aa993b 827 case language_m2:
750ba382 828 case language_pascal:
c5aa993b
JM
829 return TYPE_CODE (type) != TYPE_CODE_CHAR ? 0 : 1;
830
831 case language_c:
832 case language_cplus:
eb392fbf 833 case language_objc:
c5aa993b
JM
834 return (TYPE_CODE (type) == TYPE_CODE_INT) &&
835 TYPE_LENGTH (type) == sizeof (char)
836 ? 1 : 0;
837 default:
c906108c 838 return (0);
c5aa993b 839 }
c906108c
SS
840}
841
842/* Returns non-zero if the value is a string type */
843int
fba45db2 844string_type (struct type *type)
c906108c
SS
845{
846 CHECK_TYPEDEF (type);
c5aa993b
JM
847 switch (current_language->la_language)
848 {
db034ac5 849 /* OBSOLETE case language_chill: */
c5aa993b 850 case language_m2:
750ba382 851 case language_pascal:
c5aa993b
JM
852 return TYPE_CODE (type) != TYPE_CODE_STRING ? 0 : 1;
853
854 case language_c:
855 case language_cplus:
eb392fbf 856 case language_objc:
c906108c
SS
857 /* C does not have distinct string type. */
858 return (0);
c5aa993b 859 default:
c906108c 860 return (0);
c5aa993b 861 }
c906108c
SS
862}
863
864/* Returns non-zero if the value is a boolean type */
865int
fba45db2 866boolean_type (struct type *type)
c906108c
SS
867{
868 CHECK_TYPEDEF (type);
869 if (TYPE_CODE (type) == TYPE_CODE_BOOL)
870 return 1;
c5aa993b 871 switch (current_language->la_language)
c906108c
SS
872 {
873 case language_c:
874 case language_cplus:
eb392fbf 875 case language_objc:
db034ac5
AC
876 /* Might be more cleanly handled by having a
877 TYPE_CODE_INT_NOT_BOOL for (OBSOLETE) CHILL and such
878 languages, or a TYPE_CODE_INT_OR_BOOL for C. */
c906108c
SS
879 if (TYPE_CODE (type) == TYPE_CODE_INT)
880 return 1;
c5aa993b 881 default:
c906108c 882 break;
c5aa993b 883 }
c906108c
SS
884 return 0;
885}
886
887/* Returns non-zero if the value is a floating-point type */
888int
fba45db2 889float_type (struct type *type)
c906108c
SS
890{
891 CHECK_TYPEDEF (type);
c5aa993b 892 return TYPE_CODE (type) == TYPE_CODE_FLT;
c906108c
SS
893}
894
895/* Returns non-zero if the value is a pointer type */
896int
fba45db2 897pointer_type (struct type *type)
c906108c 898{
c5aa993b
JM
899 return TYPE_CODE (type) == TYPE_CODE_PTR ||
900 TYPE_CODE (type) == TYPE_CODE_REF;
c906108c
SS
901}
902
903/* Returns non-zero if the value is a structured type */
904int
fba45db2 905structured_type (struct type *type)
c906108c
SS
906{
907 CHECK_TYPEDEF (type);
c5aa993b
JM
908 switch (current_language->la_language)
909 {
910 case language_c:
911 case language_cplus:
eb392fbf 912 case language_objc:
c5aa993b
JM
913 return (TYPE_CODE (type) == TYPE_CODE_STRUCT) ||
914 (TYPE_CODE (type) == TYPE_CODE_UNION) ||
915 (TYPE_CODE (type) == TYPE_CODE_ARRAY);
750ba382
PM
916 case language_pascal:
917 return (TYPE_CODE(type) == TYPE_CODE_STRUCT) ||
918 (TYPE_CODE(type) == TYPE_CODE_UNION) ||
919 (TYPE_CODE(type) == TYPE_CODE_SET) ||
920 (TYPE_CODE(type) == TYPE_CODE_ARRAY);
c5aa993b
JM
921 case language_m2:
922 return (TYPE_CODE (type) == TYPE_CODE_STRUCT) ||
923 (TYPE_CODE (type) == TYPE_CODE_SET) ||
924 (TYPE_CODE (type) == TYPE_CODE_ARRAY);
db034ac5
AC
925 /* OBSOLETE case language_chill: */
926 /* OBSOLETE error ("Missing Chill support in function structured_type."); *//*FIXME */
c5aa993b 927 default:
c906108c 928 return (0);
c5aa993b 929 }
c906108c
SS
930}
931#endif
932\f
933struct type *
fba45db2 934lang_bool_type (void)
c906108c
SS
935{
936 struct symbol *sym;
937 struct type *type;
c5aa993b 938 switch (current_language->la_language)
c906108c 939 {
db034ac5
AC
940#if 0
941 /* OBSOLETE case language_chill: */
942 /* OBSOLETE return builtin_type_chill_bool; */
943#endif
c906108c
SS
944 case language_fortran:
945 sym = lookup_symbol ("logical", NULL, VAR_NAMESPACE, NULL, NULL);
946 if (sym)
947 {
948 type = SYMBOL_TYPE (sym);
949 if (type && TYPE_CODE (type) == TYPE_CODE_BOOL)
950 return type;
951 }
952 return builtin_type_f_logical_s2;
953 case language_cplus:
750ba382
PM
954 case language_pascal:
955 if (current_language->la_language==language_cplus)
956 {sym = lookup_symbol ("bool", NULL, VAR_NAMESPACE, NULL, NULL);}
957 else
958 {sym = lookup_symbol ("boolean", NULL, VAR_NAMESPACE, NULL, NULL);}
c906108c
SS
959 if (sym)
960 {
961 type = SYMBOL_TYPE (sym);
962 if (type && TYPE_CODE (type) == TYPE_CODE_BOOL)
963 return type;
964 }
965 return builtin_type_bool;
8caabe69
AG
966 case language_java:
967 sym = lookup_symbol ("boolean", NULL, VAR_NAMESPACE, NULL, NULL);
968 if (sym)
969 {
970 type = SYMBOL_TYPE (sym);
971 if (type && TYPE_CODE (type) == TYPE_CODE_BOOL)
972 return type;
973 }
974 return java_boolean_type;
c906108c
SS
975 default:
976 return builtin_type_int;
977 }
978}
979\f
980/* This page contains functions that return info about
981 (struct value) values used in GDB. */
982
983/* Returns non-zero if the value VAL represents a true value. */
984int
3d6d86c6 985value_true (struct value *val)
c906108c
SS
986{
987 /* It is possible that we should have some sort of error if a non-boolean
988 value is used in this context. Possibly dependent on some kind of
989 "boolean-checking" option like range checking. But it should probably
990 not depend on the language except insofar as is necessary to identify
991 a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean
992 should be an error, probably). */
993 return !value_logical_not (val);
994}
995\f
996/* Returns non-zero if the operator OP is defined on
997 the values ARG1 and ARG2. */
998
c5aa993b 999#if 0 /* Currently unused */
c906108c
SS
1000
1001void
3d6d86c6 1002binop_type_check (struct value *arg1, struct value *arg2, int op)
c906108c 1003{
c5aa993b 1004 struct type *t1, *t2;
c906108c 1005
c5aa993b
JM
1006 /* If we're not checking types, always return success. */
1007 if (!STRICT_TYPE)
1008 return;
1009
1010 t1 = VALUE_TYPE (arg1);
1011 if (arg2 != NULL)
1012 t2 = VALUE_TYPE (arg2);
1013 else
1014 t2 = NULL;
c906108c 1015
c5aa993b
JM
1016 switch (op)
1017 {
1018 case BINOP_ADD:
1019 case BINOP_SUB:
1020 if ((numeric_type (t1) && pointer_type (t2)) ||
1021 (pointer_type (t1) && numeric_type (t2)))
1022 {
1023 warning ("combining pointer and integer.\n");
1024 break;
1025 }
1026 case BINOP_MUL:
1027 case BINOP_LSH:
1028 case BINOP_RSH:
1029 if (!numeric_type (t1) || !numeric_type (t2))
1030 type_op_error ("Arguments to %s must be numbers.", op);
1031 else if (!same_type (t1, t2))
1032 type_op_error ("Arguments to %s must be of the same type.", op);
c906108c
SS
1033 break;
1034
c5aa993b
JM
1035 case BINOP_LOGICAL_AND:
1036 case BINOP_LOGICAL_OR:
1037 if (!boolean_type (t1) || !boolean_type (t2))
1038 type_op_error ("Arguments to %s must be of boolean type.", op);
c906108c
SS
1039 break;
1040
c5aa993b
JM
1041 case BINOP_EQUAL:
1042 if ((pointer_type (t1) && !(pointer_type (t2) || integral_type (t2))) ||
1043 (pointer_type (t2) && !(pointer_type (t1) || integral_type (t1))))
1044 type_op_error ("A pointer can only be compared to an integer or pointer.", op);
1045 else if ((pointer_type (t1) && integral_type (t2)) ||
1046 (integral_type (t1) && pointer_type (t2)))
1047 {
1048 warning ("combining integer and pointer.\n");
1049 break;
1050 }
1051 else if (!simple_type (t1) || !simple_type (t2))
1052 type_op_error ("Arguments to %s must be of simple type.", op);
1053 else if (!same_type (t1, t2))
1054 type_op_error ("Arguments to %s must be of the same type.", op);
c906108c
SS
1055 break;
1056
c5aa993b
JM
1057 case BINOP_REM:
1058 case BINOP_MOD:
1059 if (!integral_type (t1) || !integral_type (t2))
1060 type_op_error ("Arguments to %s must be of integral type.", op);
c906108c
SS
1061 break;
1062
c5aa993b
JM
1063 case BINOP_LESS:
1064 case BINOP_GTR:
1065 case BINOP_LEQ:
1066 case BINOP_GEQ:
1067 if (!ordered_type (t1) || !ordered_type (t2))
1068 type_op_error ("Arguments to %s must be of ordered type.", op);
1069 else if (!same_type (t1, t2))
1070 type_op_error ("Arguments to %s must be of the same type.", op);
c906108c
SS
1071 break;
1072
c5aa993b
JM
1073 case BINOP_ASSIGN:
1074 if (pointer_type (t1) && !integral_type (t2))
1075 type_op_error ("A pointer can only be assigned an integer.", op);
1076 else if (pointer_type (t1) && integral_type (t2))
1077 {
1078 warning ("combining integer and pointer.");
1079 break;
1080 }
1081 else if (!simple_type (t1) || !simple_type (t2))
1082 type_op_error ("Arguments to %s must be of simple type.", op);
1083 else if (!same_type (t1, t2))
1084 type_op_error ("Arguments to %s must be of the same type.", op);
c906108c
SS
1085 break;
1086
1087 case BINOP_CONCAT:
1088 /* FIXME: Needs to handle bitstrings as well. */
c5aa993b
JM
1089 if (!(string_type (t1) || character_type (t1) || integral_type (t1))
1090 || !(string_type (t2) || character_type (t2) || integral_type (t2)))
1091 type_op_error ("Arguments to %s must be strings or characters.", op);
c906108c
SS
1092 break;
1093
c5aa993b 1094 /* Unary checks -- arg2 is null */
c906108c 1095
c5aa993b
JM
1096 case UNOP_LOGICAL_NOT:
1097 if (!boolean_type (t1))
1098 type_op_error ("Argument to %s must be of boolean type.", op);
c906108c
SS
1099 break;
1100
c5aa993b
JM
1101 case UNOP_PLUS:
1102 case UNOP_NEG:
1103 if (!numeric_type (t1))
1104 type_op_error ("Argument to %s must be of numeric type.", op);
c906108c
SS
1105 break;
1106
c5aa993b
JM
1107 case UNOP_IND:
1108 if (integral_type (t1))
1109 {
1110 warning ("combining pointer and integer.\n");
1111 break;
1112 }
1113 else if (!pointer_type (t1))
1114 type_op_error ("Argument to %s must be a pointer.", op);
c906108c
SS
1115 break;
1116
c5aa993b
JM
1117 case UNOP_PREINCREMENT:
1118 case UNOP_POSTINCREMENT:
1119 case UNOP_PREDECREMENT:
1120 case UNOP_POSTDECREMENT:
1121 if (!ordered_type (t1))
1122 type_op_error ("Argument to %s must be of an ordered type.", op);
c906108c
SS
1123 break;
1124
c5aa993b 1125 default:
c906108c 1126 /* Ok. The following operators have different meanings in
c5aa993b
JM
1127 different languages. */
1128 switch (current_language->la_language)
1129 {
c906108c 1130#ifdef _LANG_c
c5aa993b
JM
1131 case language_c:
1132 case language_cplus:
eb392fbf 1133 case language_objc:
c5aa993b
JM
1134 switch (op)
1135 {
1136 case BINOP_DIV:
1137 if (!numeric_type (t1) || !numeric_type (t2))
1138 type_op_error ("Arguments to %s must be numbers.", op);
1139 break;
1140 }
1141 break;
c906108c
SS
1142#endif
1143
1144#ifdef _LANG_m2
c5aa993b
JM
1145 case language_m2:
1146 switch (op)
1147 {
1148 case BINOP_DIV:
1149 if (!float_type (t1) || !float_type (t2))
1150 type_op_error ("Arguments to %s must be floating point numbers.", op);
1151 break;
1152 case BINOP_INTDIV:
1153 if (!integral_type (t1) || !integral_type (t2))
1154 type_op_error ("Arguments to %s must be of integral type.", op);
1155 break;
1156 }
c906108c
SS
1157#endif
1158
750ba382
PM
1159#ifdef _LANG_pascal
1160 case language_pascal:
1161 switch(op)
1162 {
1163 case BINOP_DIV:
1164 if (!float_type(t1) && !float_type(t2))
1165 type_op_error ("Arguments to %s must be floating point numbers.",op);
1166 break;
1167 case BINOP_INTDIV:
1168 if (!integral_type(t1) || !integral_type(t2))
1169 type_op_error ("Arguments to %s must be of integral type.",op);
1170 break;
1171 }
1172#endif
1173
db034ac5
AC
1174#ifdef _LANG_chill /* OBSOLETE */
1175 /* OBSOLETE case language_chill: */
1176 /* OBSOLETE error ("Missing Chill support in function binop_type_check."); *//*FIXME */
c906108c
SS
1177#endif
1178
c5aa993b
JM
1179 }
1180 }
c906108c
SS
1181}
1182
c5aa993b 1183#endif /* 0 */
c906108c 1184\f
c5aa993b 1185
c906108c
SS
1186/* This page contains functions for the printing out of
1187 error messages that occur during type- and range-
1188 checking. */
1189
1190/* Prints the format string FMT with the operator as a string
1191 corresponding to the opcode OP. If FATAL is non-zero, then
1192 this is an error and error () is called. Otherwise, it is
1193 a warning and printf() is called. */
1194void
fba45db2 1195op_error (char *fmt, enum exp_opcode op, int fatal)
c906108c 1196{
c5aa993b
JM
1197 if (fatal)
1198 error (fmt, op_string (op));
1199 else
1200 {
1201 warning (fmt, op_string (op));
1202 }
c906108c
SS
1203}
1204
ddfe3c15
AC
1205/* These are called when a language fails a type- or range-check. The
1206 first argument should be a printf()-style format string, and the
1207 rest of the arguments should be its arguments. If
1208 [type|range]_check is [type|range]_check_on, an error is printed;
1209 if [type|range]_check_warn, a warning; otherwise just the
1210 message. */
c906108c
SS
1211
1212void
ddfe3c15 1213type_error (const char *string,...)
c906108c 1214{
c5aa993b 1215 va_list args;
c5aa993b 1216 va_start (args, string);
c906108c 1217
ddfe3c15
AC
1218 switch (type_check)
1219 {
1220 case type_check_warn:
1221 vwarning (string, args);
1222 break;
1223 case type_check_on:
1224 verror (string, args);
1225 break;
1226 case type_check_off:
1227 /* FIXME: cagney/2002-01-30: Should this function print anything
1228 when type error is off? */
1229 vfprintf_filtered (gdb_stderr, string, args);
1230 fprintf_filtered (gdb_stderr, "\n");
1231 break;
1232 default:
1233 internal_error (__FILE__, __LINE__, "bad switch");
1234 }
c5aa993b 1235 va_end (args);
c906108c
SS
1236}
1237
1238void
ddfe3c15 1239range_error (const char *string,...)
c906108c 1240{
c5aa993b 1241 va_list args;
c5aa993b 1242 va_start (args, string);
c906108c 1243
ddfe3c15
AC
1244 switch (range_check)
1245 {
1246 case range_check_warn:
1247 vwarning (string, args);
1248 break;
1249 case range_check_on:
1250 verror (string, args);
1251 break;
1252 case range_check_off:
1253 /* FIXME: cagney/2002-01-30: Should this function print anything
1254 when range error is off? */
1255 vfprintf_filtered (gdb_stderr, string, args);
1256 fprintf_filtered (gdb_stderr, "\n");
1257 break;
1258 default:
1259 internal_error (__FILE__, __LINE__, "bad switch");
1260 }
c5aa993b 1261 va_end (args);
c906108c 1262}
c906108c 1263\f
c5aa993b 1264
c906108c
SS
1265/* This page contains miscellaneous functions */
1266
1267/* Return the language enum for a given language string. */
1268
1269enum language
fba45db2 1270language_enum (char *str)
c906108c
SS
1271{
1272 int i;
1273
c5aa993b 1274 for (i = 0; i < languages_size; i++)
c906108c
SS
1275 if (STREQ (languages[i]->la_name, str))
1276 return languages[i]->la_language;
1277
1278 return language_unknown;
1279}
1280
1281/* Return the language struct for a given language enum. */
1282
1283const struct language_defn *
fba45db2 1284language_def (enum language lang)
c906108c
SS
1285{
1286 int i;
1287
c5aa993b
JM
1288 for (i = 0; i < languages_size; i++)
1289 {
1290 if (languages[i]->la_language == lang)
1291 {
1292 return languages[i];
1293 }
c906108c 1294 }
c906108c
SS
1295 return NULL;
1296}
1297
1298/* Return the language as a string */
1299char *
fba45db2 1300language_str (enum language lang)
c906108c
SS
1301{
1302 int i;
1303
c5aa993b
JM
1304 for (i = 0; i < languages_size; i++)
1305 {
1306 if (languages[i]->la_language == lang)
1307 {
1308 return languages[i]->la_name;
1309 }
c906108c 1310 }
c906108c
SS
1311 return "Unknown";
1312}
1313
1314static void
fba45db2 1315set_check (char *ignore, int from_tty)
c906108c 1316{
c5aa993b
JM
1317 printf_unfiltered (
1318 "\"set check\" must be followed by the name of a check subcommand.\n");
1319 help_list (setchecklist, "set check ", -1, gdb_stdout);
c906108c
SS
1320}
1321
1322static void
fba45db2 1323show_check (char *ignore, int from_tty)
c906108c 1324{
c5aa993b 1325 cmd_show_list (showchecklist, from_tty, "");
c906108c
SS
1326}
1327\f
1328/* Add a language to the set of known languages. */
1329
1330void
fba45db2 1331add_language (const struct language_defn *lang)
c906108c
SS
1332{
1333 if (lang->la_magic != LANG_MAGIC)
1334 {
c5aa993b
JM
1335 fprintf_unfiltered (gdb_stderr, "Magic number of %s language struct wrong\n",
1336 lang->la_name);
e1e9e218 1337 internal_error (__FILE__, __LINE__, "failed internal consistency check");
c906108c
SS
1338 }
1339
1340 if (!languages)
1341 {
1342 languages_allocsize = DEFAULT_ALLOCSIZE;
1343 languages = (const struct language_defn **) xmalloc
1344 (languages_allocsize * sizeof (*languages));
1345 }
1346 if (languages_size >= languages_allocsize)
1347 {
1348 languages_allocsize *= 2;
1349 languages = (const struct language_defn **) xrealloc ((char *) languages,
c5aa993b 1350 languages_allocsize * sizeof (*languages));
c906108c
SS
1351 }
1352 languages[languages_size++] = lang;
1353}
1354
1355/* Define the language that is no language. */
1356
1357static int
fba45db2 1358unk_lang_parser (void)
c906108c
SS
1359{
1360 return 1;
1361}
1362
1363static void
fba45db2 1364unk_lang_error (char *msg)
c906108c
SS
1365{
1366 error ("Attempted to parse an expression with unknown language");
1367}
1368
1369static void
fba45db2 1370unk_lang_emit_char (register int c, struct ui_file *stream, int quoter)
c906108c
SS
1371{
1372 error ("internal error - unimplemented function unk_lang_emit_char called.");
1373}
1374
1375static void
fba45db2 1376unk_lang_printchar (register int c, struct ui_file *stream)
c906108c
SS
1377{
1378 error ("internal error - unimplemented function unk_lang_printchar called.");
1379}
1380
1381static void
fba45db2
KB
1382unk_lang_printstr (struct ui_file *stream, char *string, unsigned int length,
1383 int width, int force_ellipses)
c906108c
SS
1384{
1385 error ("internal error - unimplemented function unk_lang_printstr called.");
1386}
1387
1388static struct type *
fba45db2 1389unk_lang_create_fundamental_type (struct objfile *objfile, int typeid)
c906108c
SS
1390{
1391 error ("internal error - unimplemented function unk_lang_create_fundamental_type called.");
1392}
1393
1394static void
fba45db2
KB
1395unk_lang_print_type (struct type *type, char *varstring, struct ui_file *stream,
1396 int show, int level)
c906108c
SS
1397{
1398 error ("internal error - unimplemented function unk_lang_print_type called.");
1399}
1400
1401static int
fba45db2
KB
1402unk_lang_val_print (struct type *type, char *valaddr, int embedded_offset,
1403 CORE_ADDR address, struct ui_file *stream, int format,
1404 int deref_ref, int recurse, enum val_prettyprint pretty)
c906108c
SS
1405{
1406 error ("internal error - unimplemented function unk_lang_val_print called.");
1407}
1408
1409static int
3d6d86c6 1410unk_lang_value_print (struct value *val, struct ui_file *stream, int format,
fba45db2 1411 enum val_prettyprint pretty)
c906108c
SS
1412{
1413 error ("internal error - unimplemented function unk_lang_value_print called.");
1414}
1415
6c6ea35e 1416static struct type **const (unknown_builtin_types[]) =
c5aa993b
JM
1417{
1418 0
1419};
1420static const struct op_print unk_op_print_tab[] =
1421{
1422 {NULL, OP_NULL, PREC_NULL, 0}
c906108c
SS
1423};
1424
c5aa993b
JM
1425const struct language_defn unknown_language_defn =
1426{
c906108c
SS
1427 "unknown",
1428 language_unknown,
1429 &unknown_builtin_types[0],
1430 range_check_off,
1431 type_check_off,
63872f9d 1432 case_sensitive_on,
c906108c
SS
1433 unk_lang_parser,
1434 unk_lang_error,
1435 evaluate_subexp_standard,
1436 unk_lang_printchar, /* Print character constant */
1437 unk_lang_printstr,
1438 unk_lang_emit_char,
1439 unk_lang_create_fundamental_type,
1440 unk_lang_print_type, /* Print a type using appropriate syntax */
1441 unk_lang_val_print, /* Print a value using appropriate syntax */
1442 unk_lang_value_print, /* Print a top-level value */
c5aa993b
JM
1443 {"", "", "", ""}, /* Binary format info */
1444 {"0%lo", "0", "o", ""}, /* Octal format info */
1445 {"%ld", "", "d", ""}, /* Decimal format info */
1446 {"0x%lx", "0x", "x", ""}, /* Hex format info */
c906108c
SS
1447 unk_op_print_tab, /* expression operators for printing */
1448 1, /* c-style arrays */
1449 0, /* String lower bound */
c5aa993b 1450 &builtin_type_char, /* Type of string elements */
c906108c
SS
1451 LANG_MAGIC
1452};
1453
1454/* These two structs define fake entries for the "local" and "auto" options. */
c5aa993b
JM
1455const struct language_defn auto_language_defn =
1456{
c906108c
SS
1457 "auto",
1458 language_auto,
1459 &unknown_builtin_types[0],
1460 range_check_off,
1461 type_check_off,
63872f9d 1462 case_sensitive_on,
c906108c
SS
1463 unk_lang_parser,
1464 unk_lang_error,
1465 evaluate_subexp_standard,
1466 unk_lang_printchar, /* Print character constant */
1467 unk_lang_printstr,
1468 unk_lang_emit_char,
1469 unk_lang_create_fundamental_type,
1470 unk_lang_print_type, /* Print a type using appropriate syntax */
1471 unk_lang_val_print, /* Print a value using appropriate syntax */
1472 unk_lang_value_print, /* Print a top-level value */
c5aa993b
JM
1473 {"", "", "", ""}, /* Binary format info */
1474 {"0%lo", "0", "o", ""}, /* Octal format info */
1475 {"%ld", "", "d", ""}, /* Decimal format info */
1476 {"0x%lx", "0x", "x", ""}, /* Hex format info */
c906108c
SS
1477 unk_op_print_tab, /* expression operators for printing */
1478 1, /* c-style arrays */
1479 0, /* String lower bound */
c5aa993b 1480 &builtin_type_char, /* Type of string elements */
c906108c
SS
1481 LANG_MAGIC
1482};
1483
c5aa993b
JM
1484const struct language_defn local_language_defn =
1485{
c906108c
SS
1486 "local",
1487 language_auto,
1488 &unknown_builtin_types[0],
1489 range_check_off,
1490 type_check_off,
63872f9d 1491 case_sensitive_on,
c906108c
SS
1492 unk_lang_parser,
1493 unk_lang_error,
1494 evaluate_subexp_standard,
1495 unk_lang_printchar, /* Print character constant */
1496 unk_lang_printstr,
1497 unk_lang_emit_char,
1498 unk_lang_create_fundamental_type,
1499 unk_lang_print_type, /* Print a type using appropriate syntax */
1500 unk_lang_val_print, /* Print a value using appropriate syntax */
1501 unk_lang_value_print, /* Print a top-level value */
c5aa993b
JM
1502 {"", "", "", ""}, /* Binary format info */
1503 {"0%lo", "0", "o", ""}, /* Octal format info */
1504 {"%ld", "", "d", ""}, /* Decimal format info */
1505 {"0x%lx", "0x", "x", ""}, /* Hex format info */
c906108c
SS
1506 unk_op_print_tab, /* expression operators for printing */
1507 1, /* c-style arrays */
1508 0, /* String lower bound */
c5aa993b 1509 &builtin_type_char, /* Type of string elements */
c906108c
SS
1510 LANG_MAGIC
1511};
1512\f
1513/* Initialize the language routines */
1514
1515void
fba45db2 1516_initialize_language (void)
c906108c 1517{
c5aa993b
JM
1518 struct cmd_list_element *set, *show;
1519
1520 /* GDB commands for language specific stuff */
1521
1522 set = add_set_cmd ("language", class_support, var_string_noescape,
1523 (char *) &language,
1524 "Set the current source language.",
1525 &setlist);
1526 show = add_show_from_set (set, &showlist);
9f60d481
AC
1527 set_cmd_cfunc (set, set_language_command);
1528 set_cmd_cfunc (show, show_language_command);
c5aa993b
JM
1529
1530 add_prefix_cmd ("check", no_class, set_check,
d4654627 1531 "Set the status of the type/range checker.",
c5aa993b
JM
1532 &setchecklist, "set check ", 0, &setlist);
1533 add_alias_cmd ("c", "check", no_class, 1, &setlist);
1534 add_alias_cmd ("ch", "check", no_class, 1, &setlist);
1535
1536 add_prefix_cmd ("check", no_class, show_check,
d4654627 1537 "Show the status of the type/range checker.",
c5aa993b
JM
1538 &showchecklist, "show check ", 0, &showlist);
1539 add_alias_cmd ("c", "check", no_class, 1, &showlist);
1540 add_alias_cmd ("ch", "check", no_class, 1, &showlist);
1541
1542 set = add_set_cmd ("type", class_support, var_string_noescape,
1543 (char *) &type,
1544 "Set type checking. (on/warn/off/auto)",
1545 &setchecklist);
1546 show = add_show_from_set (set, &showchecklist);
9f60d481
AC
1547 set_cmd_cfunc (set, set_type_command);
1548 set_cmd_cfunc (show, show_type_command);
c5aa993b
JM
1549
1550 set = add_set_cmd ("range", class_support, var_string_noescape,
1551 (char *) &range,
1552 "Set range checking. (on/warn/off/auto)",
1553 &setchecklist);
1554 show = add_show_from_set (set, &showchecklist);
9f60d481
AC
1555 set_cmd_cfunc (set, set_range_command);
1556 set_cmd_cfunc (show, show_range_command);
c5aa993b 1557
63872f9d
JG
1558 set = add_set_cmd ("case-sensitive", class_support, var_string_noescape,
1559 (char *) &case_sensitive,
1560 "Set case sensitivity in name search. (on/off/auto)\n\
1561For Fortran the default is off; for other languages the default is on.",
1562 &setlist);
1563 show = add_show_from_set (set, &showlist);
9f60d481
AC
1564 set_cmd_cfunc (set, set_case_command);
1565 set_cmd_cfunc (show, show_case_command);
63872f9d 1566
c5aa993b
JM
1567 add_language (&unknown_language_defn);
1568 add_language (&local_language_defn);
1569 add_language (&auto_language_defn);
1570
1571 language = savestring ("auto", strlen ("auto"));
ed9a39eb 1572 type = savestring ("auto", strlen ("auto"));
ed9a39eb 1573 range = savestring ("auto", strlen ("auto"));
63872f9d
JG
1574 case_sensitive = savestring ("auto",strlen ("auto"));
1575
1576 /* Have the above take effect */
1577 set_language (language_auto);
c906108c 1578}
This page took 0.39938 seconds and 4 git commands to generate.