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