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