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