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.
6 This file is part of GDB.
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.
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.
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, Boston, MA 02111-1307, USA. */
22 /* This file contains functions that return things that are specific
23 to languages. Each function should examine current_language if necessary,
24 and return the appropriate result. */
26 /* FIXME: Most of these would be better organized as macros which
27 return data out of a "language-specific" struct pointer that is set
28 whenever the working language changes. That would be a lot faster. */
32 #include "gdb_string.h"
33 #ifdef ANSI_PROTOTYPES
44 #include "expression.h"
47 #include "parser-defs.h"
50 show_language_command PARAMS ((char *, int));
53 set_language_command PARAMS ((char *, int));
56 show_type_command PARAMS ((char *, int));
59 set_type_command PARAMS ((char *, int));
62 show_range_command PARAMS ((char *, int));
65 set_range_command PARAMS ((char *, int));
68 set_range_str PARAMS ((void));
71 set_type_str PARAMS ((void));
74 set_lang_str PARAMS ((void));
77 unk_lang_error PARAMS ((char *));
80 unk_lang_parser PARAMS ((void));
83 show_check PARAMS ((char *, int));
86 set_check PARAMS ((char *, int));
89 set_type_range PARAMS ((void));
92 unk_lang_printchar PARAMS ((int, GDB_FILE *));
95 unk_lang_printstr PARAMS ((GDB_FILE *, char *, unsigned int, int));
98 unk_lang_create_fundamental_type PARAMS ((struct objfile *, int));
101 unk_lang_print_type PARAMS ((struct type *, char *, GDB_FILE *, int, int));
104 unk_lang_val_print PARAMS ((struct type *, char *, CORE_ADDR, GDB_FILE *,
105 int, int, int, enum val_prettyprint));
108 unk_lang_value_print PARAMS ((value_ptr, GDB_FILE *, int, enum val_prettyprint));
110 /* Forward declaration */
111 extern const struct language_defn unknown_language_defn;
112 extern char *warning_pre_print;
114 /* The current (default at startup) state of type and range checking.
115 (If the modes are set to "auto", though, these are changed based
116 on the default language at startup, and then again based on the
117 language of the first source file. */
119 enum range_mode range_mode = range_mode_auto;
120 enum range_check range_check = range_check_off;
121 enum type_mode type_mode = type_mode_auto;
122 enum type_check type_check = type_check_off;
124 /* The current language and language_mode (see language.h) */
126 const struct language_defn *current_language = &unknown_language_defn;
127 enum language_mode language_mode = language_mode_auto;
129 /* The language that the user expects to be typing in (the language
130 of main(), or the last language we notified them about, or C). */
132 const struct language_defn *expected_language;
134 /* The list of supported languages. The list itself is malloc'd. */
136 static const struct language_defn **languages;
137 static unsigned languages_size;
138 static unsigned languages_allocsize;
139 #define DEFAULT_ALLOCSIZE 4
141 /* The "set language/type/range" commands all put stuff in these
142 buffers. This is to make them work as set/show commands. The
143 user's string is copied here, then the set_* commands look at
144 them and update them to something that looks nice when it is
147 static char *language;
151 /* Warning issued when current_language and the language of the current
152 frame do not match. */
153 char lang_frame_mismatch_warn[] =
154 "Warning: the current language does not match this frame.";
157 /* This page contains the functions corresponding to GDB commands
158 and their helpers. */
160 /* Show command. Display a warning if the language set
161 does not match the frame. */
163 show_language_command (ignore, from_tty)
167 enum language flang; /* The language of the current frame */
169 flang = get_frame_language();
170 if (flang != language_unknown &&
171 language_mode == language_mode_manual &&
172 current_language->la_language != flang)
173 printf_filtered("%s\n",lang_frame_mismatch_warn);
176 /* Set command. Change the current working language. */
178 set_language_command (ignore, from_tty)
186 if (!language || !language[0])
188 printf_unfiltered("The currently understood settings are:\n\n");
189 printf_unfiltered ("local or auto Automatic setting based on source file\n");
191 for (i = 0; i < languages_size; ++i)
193 /* Already dealt with these above. */
194 if (languages[i]->la_language == language_unknown
195 || languages[i]->la_language == language_auto)
198 /* FIXME for now assume that the human-readable name is just
199 a capitalization of the internal name. */
200 printf_unfiltered ("%-16s Use the %c%s language\n",
201 languages[i]->la_name,
202 /* Capitalize first letter of language
204 toupper (languages[i]->la_name[0]),
205 languages[i]->la_name + 1);
207 /* Restore the silly string. */
208 set_language(current_language->la_language);
212 /* Search the list of languages for a match. */
213 for (i = 0; i < languages_size; i++) {
214 if (STREQ (languages[i]->la_name, language)) {
215 /* Found it! Go into manual mode, and use this language. */
216 if (languages[i]->la_language == language_auto) {
217 /* Enter auto mode. Set to the current frame's language, if known. */
218 language_mode = language_mode_auto;
219 flang = get_frame_language();
220 if (flang!=language_unknown)
222 expected_language = current_language;
225 /* Enter manual mode. Set the specified language. */
226 language_mode = language_mode_manual;
227 current_language = languages[i];
230 expected_language = current_language;
236 /* Reset the language (esp. the global string "language") to the
238 err_lang=savestring(language,strlen(language));
239 make_cleanup (free, err_lang); /* Free it after error */
240 set_language(current_language->la_language);
241 error ("Unknown language `%s'.",err_lang);
244 /* Show command. Display a warning if the type setting does
245 not match the current language. */
247 show_type_command(ignore, from_tty)
251 if (type_check != current_language->la_type_check)
253 "Warning: the current type check setting does not match the language.\n");
256 /* Set command. Change the setting for type checking. */
258 set_type_command(ignore, from_tty)
262 if (STREQ(type,"on"))
264 type_check = type_check_on;
265 type_mode = type_mode_manual;
267 else if (STREQ(type,"warn"))
269 type_check = type_check_warn;
270 type_mode = type_mode_manual;
272 else if (STREQ(type,"off"))
274 type_check = type_check_off;
275 type_mode = type_mode_manual;
277 else if (STREQ(type,"auto"))
279 type_mode = type_mode_auto;
281 /* Avoid hitting the set_type_str call below. We
282 did it in set_type_range. */
286 show_type_command((char *)NULL, from_tty);
289 /* Show command. Display a warning if the range setting does
290 not match the current language. */
292 show_range_command(ignore, from_tty)
297 if (range_check != current_language->la_range_check)
299 "Warning: the current range check setting does not match the language.\n");
302 /* Set command. Change the setting for range checking. */
304 set_range_command(ignore, from_tty)
308 if (STREQ(range,"on"))
310 range_check = range_check_on;
311 range_mode = range_mode_manual;
313 else if (STREQ(range,"warn"))
315 range_check = range_check_warn;
316 range_mode = range_mode_manual;
318 else if (STREQ(range,"off"))
320 range_check = range_check_off;
321 range_mode = range_mode_manual;
323 else if (STREQ(range,"auto"))
325 range_mode = range_mode_auto;
327 /* Avoid hitting the set_range_str call below. We
328 did it in set_type_range. */
332 show_range_command((char *)0, from_tty);
335 /* Set the status of range and type checking based on
336 the current modes and the current language.
337 If SHOW is non-zero, then print out the current language,
338 type and range checking status. */
343 if (range_mode == range_mode_auto)
344 range_check = current_language->la_range_check;
346 if (type_mode == type_mode_auto)
347 type_check = current_language->la_type_check;
353 /* Set current language to (enum language) LANG. */
361 for (i = 0; i < languages_size; i++) {
362 if (languages[i]->la_language == lang) {
363 current_language = languages[i];
371 /* This page contains functions that update the global vars
372 language, type and range. */
379 if (language_mode == language_mode_auto)
380 prefix = "auto; currently ";
382 language = concat(prefix, current_language->la_name, NULL);
388 char *tmp, *prefix = "";
391 if (type_mode==type_mode_auto)
392 prefix = "auto; currently ";
402 case type_check_warn:
406 error ("Unrecognized type check setting.");
409 type = concat(prefix,tmp,NULL);
415 char *tmp, *pref = "";
418 if (range_mode==range_mode_auto)
419 pref = "auto; currently ";
426 case range_check_off:
429 case range_check_warn:
433 error ("Unrecognized range check setting.");
436 range = concat(pref,tmp,NULL);
440 /* Print out the current language settings: language, range and
441 type checking. If QUIETLY, print only what has changed. */
444 language_info (quietly)
447 if (quietly && expected_language == current_language)
450 expected_language = current_language;
451 printf_unfiltered("Current language: %s\n",language);
452 show_language_command((char *)0, 1);
456 printf_unfiltered("Type checking: %s\n",type);
457 show_type_command((char *)0, 1);
458 printf_unfiltered("Range checking: %s\n",range);
459 show_range_command((char *)0, 1);
463 /* Return the result of a binary operation. */
465 #if 0 /* Currently unused */
468 binop_result_type (v1, v2)
472 struct type *t1 = check_typedef (VALUE_TYPE (v1));
473 struct type *t2 = check_typedef (VALUE_TYPE (v2));
475 int l1 = TYPE_LENGTH (t1);
476 int l2 = TYPE_LENGTH (t2);
478 switch(current_language->la_language)
482 if (TYPE_CODE (t1)==TYPE_CODE_FLT)
483 return TYPE_CODE(t2) == TYPE_CODE_FLT && l2 > l1 ?
484 VALUE_TYPE(v2) : VALUE_TYPE(v1);
485 else if (TYPE_CODE(t2)==TYPE_CODE_FLT)
486 return TYPE_CODE(t1)) == TYPE_CODE_FLT && l1 > l2 ?
487 VALUE_TYPE(v1) : VALUE_TYPE(v2);
488 else if (TYPE_UNSIGNED(t1) && l1 > l2)
489 return VALUE_TYPE(v1);
490 else if (TYPE_UNSIGNED(t2) && l2 > l1)
491 return VALUE_TYPE(v2);
492 else /* Both are signed. Result is the longer type */
493 return l1 > l2 ? VALUE_TYPE(v1) : VALUE_TYPE(v2);
496 /* If we are doing type-checking, l1 should equal l2, so this is
498 return l1 > l2 ? VALUE_TYPE(v1) : VALUE_TYPE(v2);
501 error ("Missing Chill support in function binop_result_check.");/*FIXME*/
504 return (struct type *)0; /* For lint */
510 /* This page contains functions that return format strings for
511 printf for printing out numbers in different formats */
513 /* Returns the appropriate printf format for hexadecimal
516 local_hex_format_custom(pre)
519 static char form[50];
521 strcpy (form, local_hex_format_prefix ());
524 strcat (form, local_hex_format_specifier ());
525 strcat (form, local_hex_format_suffix ());
529 /* Converts a number to hexadecimal and stores it in a static
530 string. Returns a pointer to this string. */
532 local_hex_string (num)
537 sprintf (res, local_hex_format(), num);
541 /* Converts a number to custom hexadecimal and stores it in a static
542 string. Returns a pointer to this string. */
544 local_hex_string_custom(num,pre)
550 sprintf (res, local_hex_format_custom(pre), num);
554 /* Returns the appropriate printf format for octal
557 local_octal_format_custom(pre)
560 static char form[50];
562 strcpy (form, local_octal_format_prefix ());
565 strcat (form, local_octal_format_specifier ());
566 strcat (form, local_octal_format_suffix ());
570 /* Returns the appropriate printf format for decimal numbers. */
572 local_decimal_format_custom(pre)
575 static char form[50];
577 strcpy (form, local_decimal_format_prefix ());
580 strcat (form, local_decimal_format_specifier ());
581 strcat (form, local_decimal_format_suffix ());
586 /* This page contains functions that are used in type/range checking.
587 They all return zero if the type/range check fails.
589 It is hoped that these will make extending GDB to parse different
590 languages a little easier. These are primarily used in eval.c when
591 evaluating expressions and making sure that their types are correct.
592 Instead of having a mess of conjucted/disjuncted expressions in an "if",
593 the ideas of type can be wrapped up in the following functions.
595 Note that some of them are not currently dependent upon which language
596 is currently being parsed. For example, floats are the same in
597 C and Modula-2 (ie. the only floating point type has TYPE_CODE of
598 TYPE_CODE_FLT), while booleans are different. */
600 /* Returns non-zero if its argument is a simple type. This is the same for
601 both Modula-2 and for C. In the C case, TYPE_CODE_CHAR will never occur,
602 and thus will never cause the failure of the test. */
607 CHECK_TYPEDEF (type);
608 switch (TYPE_CODE (type)) {
613 case TYPE_CODE_RANGE:
622 /* Returns non-zero if its argument is of an ordered type.
623 An ordered type is one in which the elements can be tested for the
624 properties of "greater than", "less than", etc, or for which the
625 operations "increment" or "decrement" make sense. */
630 CHECK_TYPEDEF (type);
631 switch (TYPE_CODE (type)) {
636 case TYPE_CODE_RANGE:
644 /* Returns non-zero if the two types are the same */
646 same_type (arg1, arg2)
647 struct type *arg1, *arg2;
649 CHECK_TYPEDEF (type);
650 if (structured_type(arg1) ? !structured_type(arg2) : structured_type(arg2))
651 /* One is structured and one isn't */
653 else if (structured_type(arg1) && structured_type(arg2))
655 else if (numeric_type(arg1) && numeric_type(arg2))
656 return (TYPE_CODE(arg2) == TYPE_CODE(arg1)) &&
657 (TYPE_UNSIGNED(arg1) == TYPE_UNSIGNED(arg2))
663 /* Returns non-zero if the type is integral */
668 CHECK_TYPEDEF (type);
669 switch(current_language->la_language)
673 return (TYPE_CODE(type) != TYPE_CODE_INT) &&
674 (TYPE_CODE(type) != TYPE_CODE_ENUM) ? 0 : 1;
676 return TYPE_CODE(type) != TYPE_CODE_INT ? 0 : 1;
678 error ("Missing Chill support in function integral_type."); /*FIXME*/
680 error ("Language not supported.");
684 /* Returns non-zero if the value is numeric */
689 CHECK_TYPEDEF (type);
690 switch (TYPE_CODE (type)) {
700 /* Returns non-zero if the value is a character type */
702 character_type (type)
705 CHECK_TYPEDEF (type);
706 switch(current_language->la_language)
710 return TYPE_CODE(type) != TYPE_CODE_CHAR ? 0 : 1;
714 return (TYPE_CODE(type) == TYPE_CODE_INT) &&
715 TYPE_LENGTH(type) == sizeof(char)
722 /* Returns non-zero if the value is a string type */
727 CHECK_TYPEDEF (type);
728 switch(current_language->la_language)
732 return TYPE_CODE(type) != TYPE_CODE_STRING ? 0 : 1;
736 /* C does not have distinct string type. */
743 /* Returns non-zero if the value is a boolean type */
748 CHECK_TYPEDEF (type);
749 if (TYPE_CODE (type) == TYPE_CODE_BOOL)
751 switch(current_language->la_language)
755 /* Might be more cleanly handled by having a TYPE_CODE_INT_NOT_BOOL
756 for CHILL and such languages, or a TYPE_CODE_INT_OR_BOOL for C. */
757 if (TYPE_CODE (type) == TYPE_CODE_INT)
765 /* Returns non-zero if the value is a floating-point type */
770 CHECK_TYPEDEF (type);
771 return TYPE_CODE(type) == TYPE_CODE_FLT;
774 /* Returns non-zero if the value is a pointer type */
779 return TYPE_CODE(type) == TYPE_CODE_PTR ||
780 TYPE_CODE(type) == TYPE_CODE_REF;
783 /* Returns non-zero if the value is a structured type */
785 structured_type(type)
788 CHECK_TYPEDEF (type);
789 switch(current_language->la_language)
793 return (TYPE_CODE(type) == TYPE_CODE_STRUCT) ||
794 (TYPE_CODE(type) == TYPE_CODE_UNION) ||
795 (TYPE_CODE(type) == TYPE_CODE_ARRAY);
797 return (TYPE_CODE(type) == TYPE_CODE_STRUCT) ||
798 (TYPE_CODE(type) == TYPE_CODE_SET) ||
799 (TYPE_CODE(type) == TYPE_CODE_ARRAY);
801 error ("Missing Chill support in function structured_type."); /*FIXME*/
813 switch(current_language->la_language)
816 return builtin_type_chill_bool;
817 case language_fortran:
818 sym = lookup_symbol ("logical", NULL, VAR_NAMESPACE, NULL, NULL);
821 type = SYMBOL_TYPE (sym);
822 if (type && TYPE_CODE (type) == TYPE_CODE_BOOL)
825 return builtin_type_f_logical_s2;
827 sym = lookup_symbol ("bool", NULL, VAR_NAMESPACE, NULL, NULL);
830 type = SYMBOL_TYPE (sym);
831 if (type && TYPE_CODE (type) == TYPE_CODE_BOOL)
834 /* ... else fall through ... */
836 return builtin_type_int;
840 /* This page contains functions that return info about
841 (struct value) values used in GDB. */
843 /* Returns non-zero if the value VAL represents a true value. */
848 /* It is possible that we should have some sort of error if a non-boolean
849 value is used in this context. Possibly dependent on some kind of
850 "boolean-checking" option like range checking. But it should probably
851 not depend on the language except insofar as is necessary to identify
852 a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean
853 should be an error, probably). */
854 return !value_logical_not (val);
857 /* Returns non-zero if the operator OP is defined on
858 the values ARG1 and ARG2. */
860 #if 0 /* Currently unused */
863 binop_type_check(arg1,arg2,op)
867 struct type *t1, *t2;
869 /* If we're not checking types, always return success. */
883 if ((numeric_type(t1) && pointer_type(t2)) ||
884 (pointer_type(t1) && numeric_type(t2)))
886 warning ("combining pointer and integer.\n");
892 if (!numeric_type(t1) || !numeric_type(t2))
893 type_op_error ("Arguments to %s must be numbers.",op);
894 else if (!same_type(t1,t2))
895 type_op_error ("Arguments to %s must be of the same type.",op);
898 case BINOP_LOGICAL_AND:
899 case BINOP_LOGICAL_OR:
900 if (!boolean_type(t1) || !boolean_type(t2))
901 type_op_error ("Arguments to %s must be of boolean type.",op);
905 if ((pointer_type(t1) && !(pointer_type(t2) || integral_type(t2))) ||
906 (pointer_type(t2) && !(pointer_type(t1) || integral_type(t1))))
907 type_op_error ("A pointer can only be compared to an integer or pointer.",op);
908 else if ((pointer_type(t1) && integral_type(t2)) ||
909 (integral_type(t1) && pointer_type(t2)))
911 warning ("combining integer and pointer.\n");
914 else if (!simple_type(t1) || !simple_type(t2))
915 type_op_error ("Arguments to %s must be of simple type.",op);
916 else if (!same_type(t1,t2))
917 type_op_error ("Arguments to %s must be of the same type.",op);
922 if (!integral_type(t1) || !integral_type(t2))
923 type_op_error ("Arguments to %s must be of integral type.",op);
930 if (!ordered_type(t1) || !ordered_type(t2))
931 type_op_error ("Arguments to %s must be of ordered type.",op);
932 else if (!same_type(t1,t2))
933 type_op_error ("Arguments to %s must be of the same type.",op);
937 if (pointer_type(t1) && !integral_type(t2))
938 type_op_error ("A pointer can only be assigned an integer.",op);
939 else if (pointer_type(t1) && integral_type(t2))
941 warning ("combining integer and pointer.");
944 else if (!simple_type(t1) || !simple_type(t2))
945 type_op_error ("Arguments to %s must be of simple type.",op);
946 else if (!same_type(t1,t2))
947 type_op_error ("Arguments to %s must be of the same type.",op);
951 /* FIXME: Needs to handle bitstrings as well. */
952 if (!(string_type(t1) || character_type(t1) || integral_type(t1))
953 || !(string_type(t2) || character_type(t2) || integral_type(t2)))
954 type_op_error ("Arguments to %s must be strings or characters.", op);
957 /* Unary checks -- arg2 is null */
959 case UNOP_LOGICAL_NOT:
960 if (!boolean_type(t1))
961 type_op_error ("Argument to %s must be of boolean type.",op);
966 if (!numeric_type(t1))
967 type_op_error ("Argument to %s must be of numeric type.",op);
971 if (integral_type(t1))
973 warning ("combining pointer and integer.\n");
976 else if (!pointer_type(t1))
977 type_op_error ("Argument to %s must be a pointer.",op);
980 case UNOP_PREINCREMENT:
981 case UNOP_POSTINCREMENT:
982 case UNOP_PREDECREMENT:
983 case UNOP_POSTDECREMENT:
984 if (!ordered_type(t1))
985 type_op_error ("Argument to %s must be of an ordered type.",op);
989 /* Ok. The following operators have different meanings in
990 different languages. */
991 switch(current_language->la_language)
999 if (!numeric_type(t1) || !numeric_type(t2))
1000 type_op_error ("Arguments to %s must be numbers.",op);
1011 if (!float_type(t1) || !float_type(t2))
1012 type_op_error ("Arguments to %s must be floating point numbers.",op);
1015 if (!integral_type(t1) || !integral_type(t2))
1016 type_op_error ("Arguments to %s must be of integral type.",op);
1022 case language_chill:
1023 error ("Missing Chill support in function binop_type_check.");/*FIXME*/
1033 /* This page contains functions for the printing out of
1034 error messages that occur during type- and range-
1037 /* Prints the format string FMT with the operator as a string
1038 corresponding to the opcode OP. If FATAL is non-zero, then
1039 this is an error and error () is called. Otherwise, it is
1040 a warning and printf() is called. */
1042 op_error (fmt,op,fatal)
1048 error (fmt,op_string(op));
1051 warning (fmt,op_string(op));
1055 /* These are called when a language fails a type- or range-check.
1056 The first argument should be a printf()-style format string, and
1057 the rest of the arguments should be its arguments. If
1058 [type|range]_check is [type|range]_check_on, then return_to_top_level()
1059 is called in the style of error (). Otherwise, the message is prefixed
1060 by the value of warning_pre_print and we do not return to the top level. */
1063 #ifdef ANSI_PROTOTYPES
1064 type_error (char *string, ...)
1066 type_error (va_alist)
1071 #ifdef ANSI_PROTOTYPES
1072 va_start (args, string);
1076 string = va_arg (args, char *);
1079 if (type_check == type_check_warn)
1080 fprintf_filtered (gdb_stderr, warning_pre_print);
1084 vfprintf_filtered (gdb_stderr, string, args);
1085 fprintf_filtered (gdb_stderr, "\n");
1087 if (type_check == type_check_on)
1088 return_to_top_level (RETURN_ERROR);
1092 #ifdef ANSI_PROTOTYPES
1093 range_error (char *string, ...)
1095 range_error (va_alist)
1100 #ifdef ANSI_PROTOTYPES
1101 va_start (args, string);
1105 string = va_arg (args, char *);
1108 if (range_check == range_check_warn)
1109 fprintf_filtered (gdb_stderr, warning_pre_print);
1113 vfprintf_filtered (gdb_stderr, string, args);
1114 fprintf_filtered (gdb_stderr, "\n");
1116 if (range_check == range_check_on)
1117 return_to_top_level (RETURN_ERROR);
1121 /* This page contains miscellaneous functions */
1123 /* Return the language struct for a given language enum. */
1125 const struct language_defn *
1131 for (i = 0; i < languages_size; i++) {
1132 if (languages[i]->la_language == lang) {
1133 return languages[i];
1139 /* Return the language as a string */
1146 for (i = 0; i < languages_size; i++) {
1147 if (languages[i]->la_language == lang) {
1148 return languages[i]->la_name;
1155 set_check (ignore, from_tty)
1160 "\"set check\" must be followed by the name of a check subcommand.\n");
1161 help_list(setchecklist, "set check ", -1, gdb_stdout);
1165 show_check (ignore, from_tty)
1169 cmd_show_list(showchecklist, from_tty, "");
1172 /* Add a language to the set of known languages. */
1176 const struct language_defn *lang;
1178 if (lang->la_magic != LANG_MAGIC)
1180 fprintf_unfiltered(gdb_stderr, "Magic number of %s language struct wrong\n",
1187 languages_allocsize = DEFAULT_ALLOCSIZE;
1188 languages = (const struct language_defn **) xmalloc
1189 (languages_allocsize * sizeof (*languages));
1191 if (languages_size >= languages_allocsize)
1193 languages_allocsize *= 2;
1194 languages = (const struct language_defn **) xrealloc ((char *) languages,
1195 languages_allocsize * sizeof (*languages));
1197 languages[languages_size++] = lang;
1200 /* Define the language that is no language. */
1209 unk_lang_error (msg)
1212 error ("Attempted to parse an expression with unknown language");
1216 unk_lang_printchar (c, stream)
1220 error ("internal error - unimplemented function unk_lang_printchar called.");
1224 unk_lang_printstr (stream, string, length, force_ellipses)
1227 unsigned int length;
1230 error ("internal error - unimplemented function unk_lang_printstr called.");
1233 static struct type *
1234 unk_lang_create_fundamental_type (objfile, typeid)
1235 struct objfile *objfile;
1238 error ("internal error - unimplemented function unk_lang_create_fundamental_type called.");
1242 unk_lang_print_type (type, varstring, stream, show, level)
1249 error ("internal error - unimplemented function unk_lang_print_type called.");
1253 unk_lang_val_print (type, valaddr, address, stream, format, deref_ref,
1262 enum val_prettyprint pretty;
1264 error ("internal error - unimplemented function unk_lang_val_print called.");
1268 unk_lang_value_print (val, stream, format, pretty)
1272 enum val_prettyprint pretty;
1274 error ("internal error - unimplemented function unk_lang_value_print called.");
1277 static struct type ** CONST_PTR (unknown_builtin_types[]) = { 0 };
1278 static const struct op_print unk_op_print_tab[] = {
1279 {NULL, OP_NULL, PREC_NULL, 0}
1282 const struct language_defn unknown_language_defn = {
1285 &unknown_builtin_types[0],
1290 evaluate_subexp_standard,
1291 unk_lang_printchar, /* Print character constant */
1293 unk_lang_create_fundamental_type,
1294 unk_lang_print_type, /* Print a type using appropriate syntax */
1295 unk_lang_val_print, /* Print a value using appropriate syntax */
1296 unk_lang_value_print, /* Print a top-level value */
1297 {"", "", "", ""}, /* Binary format info */
1298 {"0%lo", "0", "o", ""}, /* Octal format info */
1299 {"%ld", "", "d", ""}, /* Decimal format info */
1300 {"0x%lx", "0x", "x", ""}, /* Hex format info */
1301 unk_op_print_tab, /* expression operators for printing */
1302 1, /* c-style arrays */
1303 0, /* String lower bound */
1304 &builtin_type_char, /* Type of string elements */
1308 /* These two structs define fake entries for the "local" and "auto" options. */
1309 const struct language_defn auto_language_defn = {
1312 &unknown_builtin_types[0],
1317 evaluate_subexp_standard,
1318 unk_lang_printchar, /* Print character constant */
1320 unk_lang_create_fundamental_type,
1321 unk_lang_print_type, /* Print a type using appropriate syntax */
1322 unk_lang_val_print, /* Print a value using appropriate syntax */
1323 unk_lang_value_print, /* Print a top-level value */
1324 {"", "", "", ""}, /* Binary format info */
1325 {"0%lo", "0", "o", ""}, /* Octal format info */
1326 {"%ld", "", "d", ""}, /* Decimal format info */
1327 {"0x%lx", "0x", "x", ""}, /* Hex format info */
1328 unk_op_print_tab, /* expression operators for printing */
1329 1, /* c-style arrays */
1330 0, /* String lower bound */
1331 &builtin_type_char, /* Type of string elements */
1335 const struct language_defn local_language_defn = {
1338 &unknown_builtin_types[0],
1343 evaluate_subexp_standard,
1344 unk_lang_printchar, /* Print character constant */
1346 unk_lang_create_fundamental_type,
1347 unk_lang_print_type, /* Print a type using appropriate syntax */
1348 unk_lang_val_print, /* Print a value using appropriate syntax */
1349 unk_lang_value_print, /* Print a top-level value */
1350 {"", "", "", ""}, /* Binary format info */
1351 {"0%lo", "0", "o", ""}, /* Octal format info */
1352 {"%ld", "", "d", ""}, /* Decimal format info */
1353 {"0x%lx", "0x", "x", ""}, /* Hex format info */
1354 unk_op_print_tab, /* expression operators for printing */
1355 1, /* c-style arrays */
1356 0, /* String lower bound */
1357 &builtin_type_char, /* Type of string elements */
1361 /* Initialize the language routines */
1364 _initialize_language()
1366 struct cmd_list_element *set, *show;
1368 /* GDB commands for language specific stuff */
1370 set = add_set_cmd ("language", class_support, var_string_noescape,
1372 "Set the current source language.",
1374 show = add_show_from_set (set, &showlist);
1375 set->function.cfunc = set_language_command;
1376 show->function.cfunc = show_language_command;
1378 add_prefix_cmd ("check", no_class, set_check,
1379 "Set the status of the type/range checker",
1380 &setchecklist, "set check ", 0, &setlist);
1381 add_alias_cmd ("c", "check", no_class, 1, &setlist);
1382 add_alias_cmd ("ch", "check", no_class, 1, &setlist);
1384 add_prefix_cmd ("check", no_class, show_check,
1385 "Show the status of the type/range checker",
1386 &showchecklist, "show check ", 0, &showlist);
1387 add_alias_cmd ("c", "check", no_class, 1, &showlist);
1388 add_alias_cmd ("ch", "check", no_class, 1, &showlist);
1390 set = add_set_cmd ("type", class_support, var_string_noescape,
1392 "Set type checking. (on/warn/off/auto)",
1394 show = add_show_from_set (set, &showchecklist);
1395 set->function.cfunc = set_type_command;
1396 show->function.cfunc = show_type_command;
1398 set = add_set_cmd ("range", class_support, var_string_noescape,
1400 "Set range checking. (on/warn/off/auto)",
1402 show = add_show_from_set (set, &showchecklist);
1403 set->function.cfunc = set_range_command;
1404 show->function.cfunc = show_range_command;
1406 add_language (&unknown_language_defn);
1407 add_language (&local_language_defn);
1408 add_language (&auto_language_defn);
1410 language = savestring ("auto",strlen("auto"));
1411 range = savestring ("auto",strlen("auto"));
1412 type = savestring ("auto",strlen("auto"));
1414 /* Have the above take effect */
1416 set_language_command (language, 0);
1417 set_type_command (NULL, 0);
1418 set_range_command (NULL, 0);