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.
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,
21 Boston, MA 02111-1307, USA. */
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. */
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. */
33 #include "gdb_string.h"
40 #include "expression.h"
43 #include "parser-defs.h"
45 extern void _initialize_language PARAMS ((void));
48 show_language_command PARAMS ((char *, int));
51 set_language_command PARAMS ((char *, int));
54 show_type_command PARAMS ((char *, int));
57 set_type_command PARAMS ((char *, int));
60 show_range_command PARAMS ((char *, int));
63 set_range_command PARAMS ((char *, int));
66 set_range_str PARAMS ((void));
69 set_type_str PARAMS ((void));
72 set_lang_str PARAMS ((void));
75 unk_lang_error PARAMS ((char *));
78 unk_lang_parser PARAMS ((void));
81 show_check PARAMS ((char *, int));
84 set_check PARAMS ((char *, int));
87 set_type_range PARAMS ((void));
89 static void unk_lang_emit_char (int c, struct ui_file *stream, int quoter);
91 static void unk_lang_printchar (int c, struct ui_file *stream);
93 static void unk_lang_printstr (struct ui_file * stream, char *string,
94 unsigned int length, int width,
98 unk_lang_create_fundamental_type PARAMS ((struct objfile *, int));
100 static void unk_lang_print_type (struct type *, char *, struct ui_file *,
103 static int unk_lang_val_print (struct type *, char *, int, CORE_ADDR,
104 struct ui_file *, int, int, int,
105 enum val_prettyprint);
107 static int unk_lang_value_print (value_ptr, struct ui_file *, int, enum val_prettyprint);
109 /* Forward declaration */
110 extern const struct language_defn unknown_language_defn;
111 extern char *warning_pre_print;
113 /* The current (default at startup) state of type and range checking.
114 (If the modes are set to "auto", though, these are changed based
115 on the default language at startup, and then again based on the
116 language of the first source file. */
118 enum range_mode range_mode = range_mode_auto;
119 enum range_check range_check = range_check_off;
120 enum type_mode type_mode = type_mode_auto;
121 enum type_check type_check = type_check_off;
123 /* The current language and language_mode (see language.h) */
125 const struct language_defn *current_language = &unknown_language_defn;
126 enum language_mode language_mode = language_mode_auto;
128 /* The language that the user expects to be typing in (the language
129 of main(), or the last language we notified them about, or C). */
131 const struct language_defn *expected_language;
133 /* The list of supported languages. The list itself is malloc'd. */
135 static const struct language_defn **languages;
136 static unsigned languages_size;
137 static unsigned languages_allocsize;
138 #define DEFAULT_ALLOCSIZE 4
140 /* The "set language/type/range" commands all put stuff in these
141 buffers. This is to make them work as set/show commands. The
142 user's string is copied here, then the set_* commands look at
143 them and update them to something that looks nice when it is
146 static char *language;
150 /* Warning issued when current_language and the language of the current
151 frame do not match. */
152 char lang_frame_mismatch_warn[] =
153 "Warning: the current language does not match this frame.";
156 /* This page contains the functions corresponding to GDB commands
157 and their helpers. */
159 /* Show command. Display a warning if the language set
160 does not match the frame. */
162 show_language_command (ignore, from_tty)
166 enum language flang; /* The language of the current frame */
168 flang = get_frame_language ();
169 if (flang != language_unknown &&
170 language_mode == language_mode_manual &&
171 current_language->la_language != flang)
172 printf_filtered ("%s\n", lang_frame_mismatch_warn);
175 /* Set command. Change the current working language. */
177 set_language_command (ignore, from_tty)
185 if (!language || !language[0])
187 printf_unfiltered ("The currently understood settings are:\n\n");
188 printf_unfiltered ("local or auto Automatic setting based on source file\n");
190 for (i = 0; i < languages_size; ++i)
192 /* Already dealt with these above. */
193 if (languages[i]->la_language == language_unknown
194 || languages[i]->la_language == language_auto)
197 /* FIXME for now assume that the human-readable name is just
198 a capitalization of the internal name. */
199 printf_unfiltered ("%-16s Use the %c%s language\n",
200 languages[i]->la_name,
201 /* Capitalize first letter of language
203 toupper (languages[i]->la_name[0]),
204 languages[i]->la_name + 1);
206 /* Restore the silly string. */
207 set_language (current_language->la_language);
211 /* Search the list of languages for a match. */
212 for (i = 0; i < languages_size; i++)
214 if (STREQ (languages[i]->la_name, language))
216 /* Found it! Go into manual mode, and use this language. */
217 if (languages[i]->la_language == language_auto)
219 /* Enter auto mode. Set to the current frame's language, if known. */
220 language_mode = language_mode_auto;
221 flang = get_frame_language ();
222 if (flang != language_unknown)
223 set_language (flang);
224 expected_language = current_language;
229 /* Enter manual mode. Set the specified language. */
230 language_mode = language_mode_manual;
231 current_language = languages[i];
234 expected_language = current_language;
240 /* Reset the language (esp. the global string "language") to the
242 err_lang = savestring (language, strlen (language));
243 make_cleanup (free, err_lang); /* Free it after error */
244 set_language (current_language->la_language);
245 error ("Unknown language `%s'.", err_lang);
248 /* Show command. Display a warning if the type setting does
249 not match the current language. */
251 show_type_command (ignore, from_tty)
255 if (type_check != current_language->la_type_check)
257 "Warning: the current type check setting does not match the language.\n");
260 /* Set command. Change the setting for type checking. */
262 set_type_command (ignore, from_tty)
266 if (STREQ (type, "on"))
268 type_check = type_check_on;
269 type_mode = type_mode_manual;
271 else if (STREQ (type, "warn"))
273 type_check = type_check_warn;
274 type_mode = type_mode_manual;
276 else if (STREQ (type, "off"))
278 type_check = type_check_off;
279 type_mode = type_mode_manual;
281 else if (STREQ (type, "auto"))
283 type_mode = type_mode_auto;
285 /* Avoid hitting the set_type_str call below. We
286 did it in set_type_range. */
291 warning ("Unrecognized type check setting: \"%s\"", type);
294 show_type_command ((char *) NULL, from_tty);
297 /* Show command. Display a warning if the range setting does
298 not match the current language. */
300 show_range_command (ignore, from_tty)
305 if (range_check != current_language->la_range_check)
307 "Warning: the current range check setting does not match the language.\n");
310 /* Set command. Change the setting for range checking. */
312 set_range_command (ignore, from_tty)
316 if (STREQ (range, "on"))
318 range_check = range_check_on;
319 range_mode = range_mode_manual;
321 else if (STREQ (range, "warn"))
323 range_check = range_check_warn;
324 range_mode = range_mode_manual;
326 else if (STREQ (range, "off"))
328 range_check = range_check_off;
329 range_mode = range_mode_manual;
331 else if (STREQ (range, "auto"))
333 range_mode = range_mode_auto;
335 /* Avoid hitting the set_range_str call below. We
336 did it in set_type_range. */
341 warning ("Unrecognized range check setting: \"%s\"", range);
344 show_range_command ((char *) 0, from_tty);
347 /* Set the status of range and type checking based on
348 the current modes and the current language.
349 If SHOW is non-zero, then print out the current language,
350 type and range checking status. */
355 if (range_mode == range_mode_auto)
356 range_check = current_language->la_range_check;
358 if (type_mode == type_mode_auto)
359 type_check = current_language->la_type_check;
365 /* Set current language to (enum language) LANG. Returns previous language. */
372 enum language prev_language;
374 prev_language = current_language->la_language;
376 for (i = 0; i < languages_size; i++)
378 if (languages[i]->la_language == lang)
380 current_language = languages[i];
387 return prev_language;
390 /* This page contains functions that update the global vars
391 language, type and range. */
398 if (language_mode == language_mode_auto)
399 prefix = "auto; currently ";
401 language = concat (prefix, current_language->la_name, NULL);
407 char *tmp = NULL, *prefix = "";
410 if (type_mode == type_mode_auto)
411 prefix = "auto; currently ";
421 case type_check_warn:
425 error ("Unrecognized type check setting.");
428 type = concat (prefix, tmp, NULL);
434 char *tmp, *pref = "";
436 if (range_mode == range_mode_auto)
437 pref = "auto; currently ";
444 case range_check_off:
447 case range_check_warn:
451 error ("Unrecognized range check setting.");
455 range = concat (pref, tmp, NULL);
459 /* Print out the current language settings: language, range and
460 type checking. If QUIETLY, print only what has changed. */
463 language_info (quietly)
466 if (quietly && expected_language == current_language)
469 expected_language = current_language;
470 printf_unfiltered ("Current language: %s\n", language);
471 show_language_command ((char *) 0, 1);
475 printf_unfiltered ("Type checking: %s\n", type);
476 show_type_command ((char *) 0, 1);
477 printf_unfiltered ("Range checking: %s\n", range);
478 show_range_command ((char *) 0, 1);
482 /* Return the result of a binary operation. */
484 #if 0 /* Currently unused */
487 binop_result_type (v1, v2)
491 struct type *t1 = check_typedef (VALUE_TYPE (v1));
492 struct type *t2 = check_typedef (VALUE_TYPE (v2));
494 int l1 = TYPE_LENGTH (t1);
495 int l2 = TYPE_LENGTH (t2);
497 switch (current_language->la_language)
501 if (TYPE_CODE (t1) == TYPE_CODE_FLT)
502 return TYPE_CODE (t2) == TYPE_CODE_FLT && l2 > l1 ?
503 VALUE_TYPE (v2) : VALUE_TYPE (v1);
504 else if (TYPE_CODE (t2) == TYPE_CODE_FLT)
505 return TYPE_CODE (t1) == TYPE_CODE_FLT && l1 > l2 ?
506 VALUE_TYPE (v1) : VALUE_TYPE (v2);
507 else if (TYPE_UNSIGNED (t1) && l1 > l2)
508 return VALUE_TYPE (v1);
509 else if (TYPE_UNSIGNED (t2) && l2 > l1)
510 return VALUE_TYPE (v2);
511 else /* Both are signed. Result is the longer type */
512 return l1 > l2 ? VALUE_TYPE (v1) : VALUE_TYPE (v2);
515 /* If we are doing type-checking, l1 should equal l2, so this is
517 return l1 > l2 ? VALUE_TYPE (v1) : VALUE_TYPE (v2);
520 error ("Missing Chill support in function binop_result_check."); /*FIXME */
523 return (struct type *) 0; /* For lint */
529 /* This page contains functions that return format strings for
530 printf for printing out numbers in different formats */
532 /* Returns the appropriate printf format for hexadecimal
535 local_hex_format_custom (pre)
538 static char form[50];
540 strcpy (form, local_hex_format_prefix ());
543 strcat (form, local_hex_format_specifier ());
544 strcat (form, local_hex_format_suffix ());
549 /* FIXME: cagney/2000-03-04: This function does not appear to be used.
550 It can be deleted once 5.0 has been released. */
551 /* FIXME: cagney/2000-03-04: This code assumes that the compiler
552 supports ``long long''. */
553 /* Converts a number to hexadecimal (without leading "0x") and stores it in a
554 static string. Returns a pointer to this string. */
557 longest_raw_hex_string (num)
560 static char res_longest_raw_hex_string[50];
561 long long ll = num; /* MERGEBUG ?? see below */
562 res_longest_raw_hex_string[0] = 0;
563 /* MERGEBUG ?? As a quick fix I am replacing this with sprintf
564 strcat_address_numeric (num, 0, res_longest_raw_hex_string, 50);
567 sprintf (res_longest_raw_hex_string, "%llx", ll);
568 return res_longest_raw_hex_string;
572 /* Converts a number to hexadecimal and stores it in a static
573 string. Returns a pointer to this string. */
575 local_hex_string (num)
580 sprintf (res, local_hex_format (), num);
584 /* Converts a LONGEST number to hexadecimal and stores it in a static
585 string. Returns a pointer to this string. */
587 longest_local_hex_string (num)
590 return longest_local_hex_string_custom (num, "l");
593 /* Converts a number to custom hexadecimal and stores it in a static
594 string. Returns a pointer to this string. */
596 local_hex_string_custom (num, pre)
602 sprintf (res, local_hex_format_custom (pre), num);
606 /* Converts a LONGEST number to custom hexadecimal and stores it in a static
607 string. Returns a pointer to this string. Note that the width parameter
608 should end with "l", e.g. "08l" as with calls to local_hex_string_custom */
611 longest_local_hex_string_custom (num, width)
615 #define RESULT_BUF_LEN 50
616 static char res2[RESULT_BUF_LEN];
617 char format[RESULT_BUF_LEN];
618 #if !defined (PRINTF_HAS_LONG_LONG)
622 char *pad_char; /* string with one character */
625 char temp_nbr_buf[RESULT_BUF_LEN];
628 #ifndef CC_HAS_LONG_LONG
629 /* If there is no long long, then LONGEST should be just long and we
630 can use local_hex_string_custom
632 return local_hex_string_custom ((unsigned long) num, width);
635 #if defined (PRINTF_HAS_LONG_LONG)
636 /* Just use printf. */
637 strcpy (format, local_hex_format_prefix ()); /* 0x */
638 strcat (format, "%");
639 strcat (format, width); /* e.g. "08l" */
640 strcat (format, "l"); /* need "ll" for long long */
641 strcat (format, local_hex_format_specifier ()); /* "x" */
642 strcat (format, local_hex_format_suffix ()); /* "" */
643 sprintf (res2, format, num);
645 #else /* !defined (PRINTF_HAS_LONG_LONG) */
646 /* Use strcat_address_numeric to print the number into a string, then
647 build the result string from local_hex_format_prefix, padding and
648 the hex representation as indicated by "width". */
651 /* With use_local == 0, we don't get the leading "0x" prefix. */
652 /* MERGEBUG ?? As a quick fix I am replacing this call to
653 strcat_address_numeric with sprintf
654 strcat_address_numeric(num, 0, temp_nbr_buf, RESULT_BUF_LEN);
659 sprintf (temp_nbr_buf, "%llx", ll);
665 if (*parse_ptr == '-')
670 if (*parse_ptr == '0')
674 pad_char = "0"; /* If padding is on the right, it is blank */
676 field_width = atoi (parse_ptr);
677 num_len = strlen (temp_nbr_buf);
678 num_pad_chars = field_width - strlen (temp_nbr_buf); /* possibly negative */
680 if (strlen (local_hex_format_prefix ()) + num_len + num_pad_chars
681 < RESULT_BUF_LEN) /* paranoia */
682 internal_error ("longest_local_hex_string_custom: insufficient space to store result");
684 strcpy (res2, local_hex_format_prefix ());
687 while (num_pad_chars > 0)
689 strcat (res2, pad_char);
693 strcat (res2, temp_nbr_buf);
696 while (num_pad_chars > 0)
698 strcat (res2, pad_char);
705 } /* longest_local_hex_string_custom */
707 /* Returns the appropriate printf format for octal
710 local_octal_format_custom (pre)
713 static char form[50];
715 strcpy (form, local_octal_format_prefix ());
718 strcat (form, local_octal_format_specifier ());
719 strcat (form, local_octal_format_suffix ());
723 /* Returns the appropriate printf format for decimal numbers. */
725 local_decimal_format_custom (pre)
728 static char form[50];
730 strcpy (form, local_decimal_format_prefix ());
733 strcat (form, local_decimal_format_specifier ());
734 strcat (form, local_decimal_format_suffix ());
739 /* This page contains functions that are used in type/range checking.
740 They all return zero if the type/range check fails.
742 It is hoped that these will make extending GDB to parse different
743 languages a little easier. These are primarily used in eval.c when
744 evaluating expressions and making sure that their types are correct.
745 Instead of having a mess of conjucted/disjuncted expressions in an "if",
746 the ideas of type can be wrapped up in the following functions.
748 Note that some of them are not currently dependent upon which language
749 is currently being parsed. For example, floats are the same in
750 C and Modula-2 (ie. the only floating point type has TYPE_CODE of
751 TYPE_CODE_FLT), while booleans are different. */
753 /* Returns non-zero if its argument is a simple type. This is the same for
754 both Modula-2 and for C. In the C case, TYPE_CODE_CHAR will never occur,
755 and thus will never cause the failure of the test. */
760 CHECK_TYPEDEF (type);
761 switch (TYPE_CODE (type))
767 case TYPE_CODE_RANGE:
776 /* Returns non-zero if its argument is of an ordered type.
777 An ordered type is one in which the elements can be tested for the
778 properties of "greater than", "less than", etc, or for which the
779 operations "increment" or "decrement" make sense. */
784 CHECK_TYPEDEF (type);
785 switch (TYPE_CODE (type))
791 case TYPE_CODE_RANGE:
799 /* Returns non-zero if the two types are the same */
801 same_type (arg1, arg2)
802 struct type *arg1, *arg2;
804 CHECK_TYPEDEF (type);
805 if (structured_type (arg1) ? !structured_type (arg2) : structured_type (arg2))
806 /* One is structured and one isn't */
808 else if (structured_type (arg1) && structured_type (arg2))
810 else if (numeric_type (arg1) && numeric_type (arg2))
811 return (TYPE_CODE (arg2) == TYPE_CODE (arg1)) &&
812 (TYPE_UNSIGNED (arg1) == TYPE_UNSIGNED (arg2))
818 /* Returns non-zero if the type is integral */
823 CHECK_TYPEDEF (type);
824 switch (current_language->la_language)
828 return (TYPE_CODE (type) != TYPE_CODE_INT) &&
829 (TYPE_CODE (type) != TYPE_CODE_ENUM) ? 0 : 1;
831 return TYPE_CODE (type) != TYPE_CODE_INT ? 0 : 1;
833 error ("Missing Chill support in function integral_type."); /*FIXME */
835 error ("Language not supported.");
839 /* Returns non-zero if the value is numeric */
844 CHECK_TYPEDEF (type);
845 switch (TYPE_CODE (type))
856 /* Returns non-zero if the value is a character type */
858 character_type (type)
861 CHECK_TYPEDEF (type);
862 switch (current_language->la_language)
866 return TYPE_CODE (type) != TYPE_CODE_CHAR ? 0 : 1;
870 return (TYPE_CODE (type) == TYPE_CODE_INT) &&
871 TYPE_LENGTH (type) == sizeof (char)
878 /* Returns non-zero if the value is a string type */
883 CHECK_TYPEDEF (type);
884 switch (current_language->la_language)
888 return TYPE_CODE (type) != TYPE_CODE_STRING ? 0 : 1;
892 /* C does not have distinct string type. */
899 /* Returns non-zero if the value is a boolean type */
904 CHECK_TYPEDEF (type);
905 if (TYPE_CODE (type) == TYPE_CODE_BOOL)
907 switch (current_language->la_language)
911 /* Might be more cleanly handled by having a TYPE_CODE_INT_NOT_BOOL
912 for CHILL and such languages, or a TYPE_CODE_INT_OR_BOOL for C. */
913 if (TYPE_CODE (type) == TYPE_CODE_INT)
921 /* Returns non-zero if the value is a floating-point type */
926 CHECK_TYPEDEF (type);
927 return TYPE_CODE (type) == TYPE_CODE_FLT;
930 /* Returns non-zero if the value is a pointer type */
935 return TYPE_CODE (type) == TYPE_CODE_PTR ||
936 TYPE_CODE (type) == TYPE_CODE_REF;
939 /* Returns non-zero if the value is a structured type */
941 structured_type (type)
944 CHECK_TYPEDEF (type);
945 switch (current_language->la_language)
949 return (TYPE_CODE (type) == TYPE_CODE_STRUCT) ||
950 (TYPE_CODE (type) == TYPE_CODE_UNION) ||
951 (TYPE_CODE (type) == TYPE_CODE_ARRAY);
953 return (TYPE_CODE (type) == TYPE_CODE_STRUCT) ||
954 (TYPE_CODE (type) == TYPE_CODE_SET) ||
955 (TYPE_CODE (type) == TYPE_CODE_ARRAY);
957 error ("Missing Chill support in function structured_type."); /*FIXME */
969 switch (current_language->la_language)
972 return builtin_type_chill_bool;
973 case language_fortran:
974 sym = lookup_symbol ("logical", NULL, VAR_NAMESPACE, NULL, NULL);
977 type = SYMBOL_TYPE (sym);
978 if (type && TYPE_CODE (type) == TYPE_CODE_BOOL)
981 return builtin_type_f_logical_s2;
983 sym = lookup_symbol ("bool", NULL, VAR_NAMESPACE, NULL, NULL);
986 type = SYMBOL_TYPE (sym);
987 if (type && TYPE_CODE (type) == TYPE_CODE_BOOL)
990 return builtin_type_bool;
992 return builtin_type_int;
996 /* This page contains functions that return info about
997 (struct value) values used in GDB. */
999 /* Returns non-zero if the value VAL represents a true value. */
1004 /* It is possible that we should have some sort of error if a non-boolean
1005 value is used in this context. Possibly dependent on some kind of
1006 "boolean-checking" option like range checking. But it should probably
1007 not depend on the language except insofar as is necessary to identify
1008 a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean
1009 should be an error, probably). */
1010 return !value_logical_not (val);
1013 /* Returns non-zero if the operator OP is defined on
1014 the values ARG1 and ARG2. */
1016 #if 0 /* Currently unused */
1019 binop_type_check (arg1, arg2, op)
1020 value_ptr arg1, arg2;
1023 struct type *t1, *t2;
1025 /* If we're not checking types, always return success. */
1029 t1 = VALUE_TYPE (arg1);
1031 t2 = VALUE_TYPE (arg2);
1039 if ((numeric_type (t1) && pointer_type (t2)) ||
1040 (pointer_type (t1) && numeric_type (t2)))
1042 warning ("combining pointer and integer.\n");
1048 if (!numeric_type (t1) || !numeric_type (t2))
1049 type_op_error ("Arguments to %s must be numbers.", op);
1050 else if (!same_type (t1, t2))
1051 type_op_error ("Arguments to %s must be of the same type.", op);
1054 case BINOP_LOGICAL_AND:
1055 case BINOP_LOGICAL_OR:
1056 if (!boolean_type (t1) || !boolean_type (t2))
1057 type_op_error ("Arguments to %s must be of boolean type.", op);
1061 if ((pointer_type (t1) && !(pointer_type (t2) || integral_type (t2))) ||
1062 (pointer_type (t2) && !(pointer_type (t1) || integral_type (t1))))
1063 type_op_error ("A pointer can only be compared to an integer or pointer.", op);
1064 else if ((pointer_type (t1) && integral_type (t2)) ||
1065 (integral_type (t1) && pointer_type (t2)))
1067 warning ("combining integer and pointer.\n");
1070 else if (!simple_type (t1) || !simple_type (t2))
1071 type_op_error ("Arguments to %s must be of simple type.", op);
1072 else if (!same_type (t1, t2))
1073 type_op_error ("Arguments to %s must be of the same type.", op);
1078 if (!integral_type (t1) || !integral_type (t2))
1079 type_op_error ("Arguments to %s must be of integral type.", op);
1086 if (!ordered_type (t1) || !ordered_type (t2))
1087 type_op_error ("Arguments to %s must be of ordered type.", op);
1088 else if (!same_type (t1, t2))
1089 type_op_error ("Arguments to %s must be of the same type.", op);
1093 if (pointer_type (t1) && !integral_type (t2))
1094 type_op_error ("A pointer can only be assigned an integer.", op);
1095 else if (pointer_type (t1) && integral_type (t2))
1097 warning ("combining integer and pointer.");
1100 else if (!simple_type (t1) || !simple_type (t2))
1101 type_op_error ("Arguments to %s must be of simple type.", op);
1102 else if (!same_type (t1, t2))
1103 type_op_error ("Arguments to %s must be of the same type.", op);
1107 /* FIXME: Needs to handle bitstrings as well. */
1108 if (!(string_type (t1) || character_type (t1) || integral_type (t1))
1109 || !(string_type (t2) || character_type (t2) || integral_type (t2)))
1110 type_op_error ("Arguments to %s must be strings or characters.", op);
1113 /* Unary checks -- arg2 is null */
1115 case UNOP_LOGICAL_NOT:
1116 if (!boolean_type (t1))
1117 type_op_error ("Argument to %s must be of boolean type.", op);
1122 if (!numeric_type (t1))
1123 type_op_error ("Argument to %s must be of numeric type.", op);
1127 if (integral_type (t1))
1129 warning ("combining pointer and integer.\n");
1132 else if (!pointer_type (t1))
1133 type_op_error ("Argument to %s must be a pointer.", op);
1136 case UNOP_PREINCREMENT:
1137 case UNOP_POSTINCREMENT:
1138 case UNOP_PREDECREMENT:
1139 case UNOP_POSTDECREMENT:
1140 if (!ordered_type (t1))
1141 type_op_error ("Argument to %s must be of an ordered type.", op);
1145 /* Ok. The following operators have different meanings in
1146 different languages. */
1147 switch (current_language->la_language)
1151 case language_cplus:
1155 if (!numeric_type (t1) || !numeric_type (t2))
1156 type_op_error ("Arguments to %s must be numbers.", op);
1167 if (!float_type (t1) || !float_type (t2))
1168 type_op_error ("Arguments to %s must be floating point numbers.", op);
1171 if (!integral_type (t1) || !integral_type (t2))
1172 type_op_error ("Arguments to %s must be of integral type.", op);
1178 case language_chill:
1179 error ("Missing Chill support in function binop_type_check."); /*FIXME */
1189 /* This page contains functions for the printing out of
1190 error messages that occur during type- and range-
1193 /* Prints the format string FMT with the operator as a string
1194 corresponding to the opcode OP. If FATAL is non-zero, then
1195 this is an error and error () is called. Otherwise, it is
1196 a warning and printf() is called. */
1198 op_error (fmt, op, fatal)
1204 error (fmt, op_string (op));
1207 warning (fmt, op_string (op));
1211 /* These are called when a language fails a type- or range-check.
1212 The first argument should be a printf()-style format string, and
1213 the rest of the arguments should be its arguments. If
1214 [type|range]_check is [type|range]_check_on, then return_to_top_level()
1215 is called in the style of error (). Otherwise, the message is prefixed
1216 by the value of warning_pre_print and we do not return to the top level. */
1219 type_error (char *string,...)
1222 va_start (args, string);
1224 if (type_check == type_check_warn)
1225 fprintf_filtered (gdb_stderr, warning_pre_print);
1229 vfprintf_filtered (gdb_stderr, string, args);
1230 fprintf_filtered (gdb_stderr, "\n");
1232 if (type_check == type_check_on)
1233 return_to_top_level (RETURN_ERROR);
1237 range_error (char *string,...)
1240 va_start (args, string);
1242 if (range_check == range_check_warn)
1243 fprintf_filtered (gdb_stderr, warning_pre_print);
1247 vfprintf_filtered (gdb_stderr, string, args);
1248 fprintf_filtered (gdb_stderr, "\n");
1250 if (range_check == range_check_on)
1251 return_to_top_level (RETURN_ERROR);
1255 /* This page contains miscellaneous functions */
1257 /* Return the language enum for a given language string. */
1265 for (i = 0; i < languages_size; i++)
1266 if (STREQ (languages[i]->la_name, str))
1267 return languages[i]->la_language;
1269 return language_unknown;
1272 /* Return the language struct for a given language enum. */
1274 const struct language_defn *
1280 for (i = 0; i < languages_size; i++)
1282 if (languages[i]->la_language == lang)
1284 return languages[i];
1290 /* Return the language as a string */
1297 for (i = 0; i < languages_size; i++)
1299 if (languages[i]->la_language == lang)
1301 return languages[i]->la_name;
1308 set_check (ignore, from_tty)
1313 "\"set check\" must be followed by the name of a check subcommand.\n");
1314 help_list (setchecklist, "set check ", -1, gdb_stdout);
1318 show_check (ignore, from_tty)
1322 cmd_show_list (showchecklist, from_tty, "");
1325 /* Add a language to the set of known languages. */
1329 const struct language_defn *lang;
1331 if (lang->la_magic != LANG_MAGIC)
1333 fprintf_unfiltered (gdb_stderr, "Magic number of %s language struct wrong\n",
1340 languages_allocsize = DEFAULT_ALLOCSIZE;
1341 languages = (const struct language_defn **) xmalloc
1342 (languages_allocsize * sizeof (*languages));
1344 if (languages_size >= languages_allocsize)
1346 languages_allocsize *= 2;
1347 languages = (const struct language_defn **) xrealloc ((char *) languages,
1348 languages_allocsize * sizeof (*languages));
1350 languages[languages_size++] = lang;
1353 /* Define the language that is no language. */
1362 unk_lang_error (msg)
1365 error ("Attempted to parse an expression with unknown language");
1369 unk_lang_emit_char (c, stream, quoter)
1371 struct ui_file *stream;
1374 error ("internal error - unimplemented function unk_lang_emit_char called.");
1378 unk_lang_printchar (c, stream)
1380 struct ui_file *stream;
1382 error ("internal error - unimplemented function unk_lang_printchar called.");
1386 unk_lang_printstr (stream, string, length, width, force_ellipses)
1387 struct ui_file *stream;
1389 unsigned int length;
1393 error ("internal error - unimplemented function unk_lang_printstr called.");
1396 static struct type *
1397 unk_lang_create_fundamental_type (objfile, typeid)
1398 struct objfile *objfile;
1401 error ("internal error - unimplemented function unk_lang_create_fundamental_type called.");
1405 unk_lang_print_type (type, varstring, stream, show, level)
1408 struct ui_file *stream;
1412 error ("internal error - unimplemented function unk_lang_print_type called.");
1416 unk_lang_val_print (type, valaddr, embedded_offset, address, stream, format, deref_ref,
1420 int embedded_offset;
1422 struct ui_file *stream;
1426 enum val_prettyprint pretty;
1428 error ("internal error - unimplemented function unk_lang_val_print called.");
1432 unk_lang_value_print (val, stream, format, pretty)
1434 struct ui_file *stream;
1436 enum val_prettyprint pretty;
1438 error ("internal error - unimplemented function unk_lang_value_print called.");
1441 static struct type **CONST_PTR (unknown_builtin_types[]) =
1445 static const struct op_print unk_op_print_tab[] =
1447 {NULL, OP_NULL, PREC_NULL, 0}
1450 const struct language_defn unknown_language_defn =
1454 &unknown_builtin_types[0],
1459 evaluate_subexp_standard,
1460 unk_lang_printchar, /* Print character constant */
1463 unk_lang_create_fundamental_type,
1464 unk_lang_print_type, /* Print a type using appropriate syntax */
1465 unk_lang_val_print, /* Print a value using appropriate syntax */
1466 unk_lang_value_print, /* Print a top-level value */
1467 {"", "", "", ""}, /* Binary format info */
1468 {"0%lo", "0", "o", ""}, /* Octal format info */
1469 {"%ld", "", "d", ""}, /* Decimal format info */
1470 {"0x%lx", "0x", "x", ""}, /* Hex format info */
1471 unk_op_print_tab, /* expression operators for printing */
1472 1, /* c-style arrays */
1473 0, /* String lower bound */
1474 &builtin_type_char, /* Type of string elements */
1478 /* These two structs define fake entries for the "local" and "auto" options. */
1479 const struct language_defn auto_language_defn =
1483 &unknown_builtin_types[0],
1488 evaluate_subexp_standard,
1489 unk_lang_printchar, /* Print character constant */
1492 unk_lang_create_fundamental_type,
1493 unk_lang_print_type, /* Print a type using appropriate syntax */
1494 unk_lang_val_print, /* Print a value using appropriate syntax */
1495 unk_lang_value_print, /* Print a top-level value */
1496 {"", "", "", ""}, /* Binary format info */
1497 {"0%lo", "0", "o", ""}, /* Octal format info */
1498 {"%ld", "", "d", ""}, /* Decimal format info */
1499 {"0x%lx", "0x", "x", ""}, /* Hex format info */
1500 unk_op_print_tab, /* expression operators for printing */
1501 1, /* c-style arrays */
1502 0, /* String lower bound */
1503 &builtin_type_char, /* Type of string elements */
1507 const struct language_defn local_language_defn =
1511 &unknown_builtin_types[0],
1516 evaluate_subexp_standard,
1517 unk_lang_printchar, /* Print character constant */
1520 unk_lang_create_fundamental_type,
1521 unk_lang_print_type, /* Print a type using appropriate syntax */
1522 unk_lang_val_print, /* Print a value using appropriate syntax */
1523 unk_lang_value_print, /* Print a top-level value */
1524 {"", "", "", ""}, /* Binary format info */
1525 {"0%lo", "0", "o", ""}, /* Octal format info */
1526 {"%ld", "", "d", ""}, /* Decimal format info */
1527 {"0x%lx", "0x", "x", ""}, /* Hex format info */
1528 unk_op_print_tab, /* expression operators for printing */
1529 1, /* c-style arrays */
1530 0, /* String lower bound */
1531 &builtin_type_char, /* Type of string elements */
1535 /* Initialize the language routines */
1538 _initialize_language ()
1540 struct cmd_list_element *set, *show;
1542 /* GDB commands for language specific stuff */
1544 set = add_set_cmd ("language", class_support, var_string_noescape,
1546 "Set the current source language.",
1548 show = add_show_from_set (set, &showlist);
1549 set->function.cfunc = set_language_command;
1550 show->function.cfunc = show_language_command;
1552 add_prefix_cmd ("check", no_class, set_check,
1553 "Set the status of the type/range checker",
1554 &setchecklist, "set check ", 0, &setlist);
1555 add_alias_cmd ("c", "check", no_class, 1, &setlist);
1556 add_alias_cmd ("ch", "check", no_class, 1, &setlist);
1558 add_prefix_cmd ("check", no_class, show_check,
1559 "Show the status of the type/range checker",
1560 &showchecklist, "show check ", 0, &showlist);
1561 add_alias_cmd ("c", "check", no_class, 1, &showlist);
1562 add_alias_cmd ("ch", "check", no_class, 1, &showlist);
1564 set = add_set_cmd ("type", class_support, var_string_noescape,
1566 "Set type checking. (on/warn/off/auto)",
1568 show = add_show_from_set (set, &showchecklist);
1569 set->function.cfunc = set_type_command;
1570 show->function.cfunc = show_type_command;
1572 set = add_set_cmd ("range", class_support, var_string_noescape,
1574 "Set range checking. (on/warn/off/auto)",
1576 show = add_show_from_set (set, &showchecklist);
1577 set->function.cfunc = set_range_command;
1578 show->function.cfunc = show_range_command;
1580 add_language (&unknown_language_defn);
1581 add_language (&local_language_defn);
1582 add_language (&auto_language_defn);
1584 language = savestring ("auto", strlen ("auto"));
1585 set_language_command (language, 0);
1587 type = savestring ("auto", strlen ("auto"));
1588 set_type_command (NULL, 0);
1590 range = savestring ("auto", strlen ("auto"));
1591 set_range_command (NULL, 0);